我在将多行保存到后端时遇到问题。我不知道如何批量发送所有行,因此我试图一次发送每一行,但是在将最后一行放入oEntry之后会命中。

submitButtonPress: function() {
var oModel = this.getModel();
var hasChanges = oModel.hasPendingChanges();

if (hasChanges) {
    var mcJson = {};
            //get only rows with changes
    var modelChanges = oModel.getPendingChanges();
    mcJson = modelChanges;

    var mcJsonLength = Object.keys(mcJson).length;
    var mcJsonKey = Object.keys(mcJson);
    var officeCode = this.byId("officeCombo").getValue();
    var oEntry = {};

   //for each row get data
for (var i = 0; i < mcJsonLength; i++) {
    var item = mcJsonKey[i];
    var obj = modelChanges[item];
    var estDate = this.convertDate(obj.ESTIMATE_DATE);

            oEntry.MRU_ID = obj.EST_MRU_ID.toString();
    oEntry.ESTIMATE_PRCT = obj.ESTIMATE_PRCT;
    oEntry.INSTALL_READ = obj.INSTALL_READ;
    oEntry.PLAN_ESTIMATE = obj.EST_INSTALL;
    oEntry.MRU_DATE = estDate;
    oEntry.OFFICE_CODE = officeCode.toString();*/


oModel.create("/MRU_ESTSet", oEntry, {
    success: function(oData, response) {
       sap.m.MessageBox.alert("MRU: " + oEntry.MRU_ID + " EST DATE:" + oEntry.MRU_DATE + " SAVED!");},
error: function(oError) {
    sap.m.MessageBox.alert("Error Saving Entries!!");
}
});

}
} else {
sap.m.MessageBox.alert("No Changes To Submit");
}


}

最佳答案

如果您使用的是oDataModel V2,则只需执行以下操作:

oModel.submitChanges()


这将批量发送对模型所做的所有更改。

submitChanges method documentation

关于javascript - 将表中的多行保存到后端SAPUI5,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48549023/

10-11 13:58