简体   繁体   English

SAPUI5 odata.v2.ODataModel 批量请求完成前调用批量请求回调

[英]SAPUI5 odata.v2.ODataModel Call back of batch request is invoked before batch request is complete

I'm having a little issue with my batch request, when the odata model is submitted and triggered, the that.readAndUpdateSercicePeriodPlans(oService).then(function(oSerciceO) in the callback is triggered before the batch return the result我的批处理请求有点问题,当提交并触发 odata 模型时,在批处理返回结果之前触发回调中的that.readAndUpdateSercicePeriodPlans(oService).then(function(oSerciceO)

As you can see using my debugger, the call back function is triggered :正如您使用我的调试器所看到的,回调函数被触发:

在此处输入图片说明

but the network didn't return the result yet :但网络还没有返回结果:

在此处输入图片说明

Below is the code, what I am doing wrong?下面是代码,我做错了什么? :

odataMod = this.getModel("Service");
odataMod.setUseBatch(true);
var aDeffGroup = odataMod.getDeferredGroups();
//add your deffered group
aDeffGroup.push("deletionGroup");
_.forEach(periodPlanArr, function(periodPlanToDel) {
    odataMod.remove('/ProjectTaskServicePeriodPlanCollection(\'' + periodPlanToDel.ObjectID + '\')/', {
        groupId: "deletionGroup"
    });
});

oGlobalBusyDialog.setText("Deleting Period Plans in progress");
oGlobalBusyDialog.setTitle("Updating data Model");
oGlobalBusyDialog.open();
//This trigger the batch request 
odataMod.submitChanges({
            // deffered group id
            groupId: "deletionGroup",
            success: function(oData) {
                sap.m.MessageToast.show(oData.toString());
                var aErrorData = sap.ui.getCore().getMessageManager().getMessageModel();
                var msg = aErrorData.getData();
                var oService = _.find(oNoneAssignedTaskModelData, function(oSewrv) {
                    return oSewrv.ObjectID === uniqueByID[0].ParentObjectID;
                });
                oGlobalBusyDialog.setText("Updating oModel in progress");
                oGlobalBusyDialog.setTitle("Updating data Model");
                // ISSUE : This below  function is invoked before even the batch request is complete , why ?! 
                that.readAndUpdateSercicePeriodPlans(oService).then(function(oSerciceO) {
                        oGlobalBusyDialog.close();
                        //Logic USER STORY 3423: Get Internal Indicator PeriodPlan and update the employee nternal Indicator PeriodPlan

                    },
                    error: function(oError) {
                        var oResponse = JSON.parse(oError.response.body);
                        sap.m.MessageToast.show("Fehler: " + oResponse.error.message.value);
                    }

                });

只有当过滤器中有某些值时,您的 Chrome 过滤器图标才会显示为红色。:)

After debugging all night and drinkind redbull I've finally found the issue :经过整夜调试和drinkind redbull,我终于找到了问题所在:

var aDeffGroup = odataMod.getDeferredGroups();
aDeffGroup.push("deletionGroup");
//I must set the deffered groups after pushing the ID or else it won't be added 
this.setDeferredGroups(aDeffGroup);

I'd recommand to avoid adding same group twice - I had some issues because of that.我建议避免两次添加同一组-因此我遇到了一些问题。

     odataMod = this.getModel("Service");
            odataMod.setUseBatch(true);
            //var aDeffGroup = odataMod.getDeferredGroups();
            //aDeffGroup.push("deletionGroup");
            that.setModelDeferredGroup(odataMod, "deletionGroup");
// the function 
    setModelDeferredGroup: function (oModel, sGroup) {
        if (oModel && sGroup) {
            var aDeferredGroups = oModel.getDeferredGroups();
            if (aDeferredGroups.indexOf(sGroup) < 0) {
                aDeferredGroups.push(sGroup);
                oModel.setDeferredGroups(aDeferredGroups);
            }
        }
    }   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM