与sap.ui.model.odata.v2.ODataModel sapui5批

时间:2021-01-23 16:21:12

I created table with data using JSONModel

我使用JSONModel创建了表

    var oModel = new sap.ui.model.json.JSONModel(query);
    oTablePrio = sap.ui.getCore().getControl("idTablePrio2");
    oTablePrio.setModel(oModel, "Prio2"); 

Everythink look and work good.

每个人的想法都很好。

Now i have added new column(prio) where i will change value. After changing i would like to save every rows( in the SAP ztable ) after clicking buton save . I made something like this

现在我添加了新的列(prio),我将在其中更改值。在更改之后,我希望在单击buton save后保存每一行(在SAP ztable中)。我做了这样的东西

var oModel = new sap.ui.model.odata.v2.ODataModel(gServiceUrl);
        oModel.setUseBatch(true);
        for (var i = 0; i < data.length; i++) {
            sEntry.Matnr = data[i].Matnr;
            sEntry.Bbynr = data[i].Bbynr;
            sEntry.Prio = data[i].Prio;

oModel.update("/WielosztSet('"+data[i].Bbynr+"')", sEntry, {
                  method: "PUT",  function(){
                alert('Data Updated Successfully');
                 location.reload(true);
                  },function(){
                        sap.m.MessageToast.show('Update failed',{duration:1000});

                  }});
}

Now only it sends data only with the last row. I wrote that i cannot update more than one row in this way and I need to make batch. I connot find how to create working batch for uploding data with sap.ui.model.odata.v2.ODataModel

现在只有它只发送最后一行的数据。我写道,我不能以这种方式更新超过一行,我需要做批次。我不知道如何使用sap.ui.model.odata.v2.ODataModel创建工作批处理

Please give me some advice.

请给我一些建议。

1 个解决方案

#1


0  

Before the call of the oModel.update assign the UseBatch to true:

在奥莫德尔的呼唤之前。更新将UseBatch赋为true:

oModel.setUseBatch(true);

Make your for:

让你的:

for (var i = 0; i < data.length; i++) {
            sEntry.Matnr = data[i].Matnr;
            sEntry.Bbynr = data[i].Bbynr;
            sEntry.Prio = data[i].Prio;

oModel.update("/WielosztSet('"+data[i].Bbynr+"')", sEntry, {
                  method: "PUT",  function(){
                alert('Data Updated Successfully');
                 location.reload(true);
                  },function(){
                        sap.m.MessageToast.show('Update failed',{duration:1000});

                  }});
}

At the end of for put the submitChanges.

在最后,提交变更。

oModel.submitChanges();
oModel.setUseBatch(false); // Make false if you reuse this oModel.

Regards.

的问候。

#1


0  

Before the call of the oModel.update assign the UseBatch to true:

在奥莫德尔的呼唤之前。更新将UseBatch赋为true:

oModel.setUseBatch(true);

Make your for:

让你的:

for (var i = 0; i < data.length; i++) {
            sEntry.Matnr = data[i].Matnr;
            sEntry.Bbynr = data[i].Bbynr;
            sEntry.Prio = data[i].Prio;

oModel.update("/WielosztSet('"+data[i].Bbynr+"')", sEntry, {
                  method: "PUT",  function(){
                alert('Data Updated Successfully');
                 location.reload(true);
                  },function(){
                        sap.m.MessageToast.show('Update failed',{duration:1000});

                  }});
}

At the end of for put the submitChanges.

在最后,提交变更。

oModel.submitChanges();
oModel.setUseBatch(false); // Make false if you reuse this oModel.

Regards.

的问候。