简体   繁体   English

SAPUI5未完成更改丢失

[英]SAPUI5 pendingChanges get lost

i am working on an SAPUI5 App with odata-services. 我正在使用带有odata-services的SAPUI5应用程序。 To avoid the loss of changes in case of an error while updating an EntitySet i have a function call before. 为了避免在更新EntitySet时发生错误时丢失更改,我之前有一个函数调用。 This functionCall calls the same code as the update method of the entity but without commit. 此functionCall调用与实体的update方法相同的代码,但没有提交。 In the success-Method of the function call i call the submitChanges-Method. 在函数调用的成功方法中,我调用了commitChanges-Method。 This works fine but now i have a problem with some fields. 这工作正常,但现在我在某些领域存在问题。 I change two fields and found the changes in the model (oModel.getPendingChanges). 我更改了两个字段,并发现了模型中的更改(oModel.getPendingChanges)。 After the call of the functionCall some changes get lost. 调用函数之后,一些更改会丢失。 In this case one of the changes gets lost and the other one is still visible in the model. 在这种情况下,其中一项更改会丢失,而另一项更改仍在模型中可见。 Here is my save-method: 这是我的保存方法:

    onSavePressed: function() {
            if (this.getView().getModel().hasPendingChanges()) {
                var oChanges = new sap.ui.model.json.JSONModel();
                oChanges.setData(this.getView().getModel().getProperty("/" + this.sPath));


                this.getView().getModel().callFunction("/CheckData", {
                    method: "GET",
                    urlParameters: {
                        param1: oChanges.oData.param1,
                        param2: oChanges.oData.param2,
                        param3: oChanges.oData.param3,
                        param4: oChanges.oData.param4
                    },
                    success: function(oData, response) {
                        this.getView().getModel().submitChanges({
                            success: function(oData, oResponse) {                                   
                                sap.m.MessageToast.show(this.getView().getModel("i18n").getResourceBundle().getText("DATA_SAVED"));
                            }.bind(this),
                            error: function(oError) {
                                console.log(oError);
                            }.bind(this)
                        });
                    }.bind(this),
                    error: function(oError) {
                        console.log(oError);
                    }.bind(this)
                });
            }

        },

Do you have an idea why this changes get lost or how to avoid the loss of this changes? 您是否知道为什么这些更改会丢失或如何避免丢失这些更改?

Found the reason for the Problem. 找到了问题的原因。 Just should have read the documentation for callFunction: If the return type of the function import is either an entity type or a collection of an entity type, then the changes are reflected in the model 只是应该阅读callFunction的文档: 如果函数导入的返回类型是实体类型或实体类型的集合,则更改将反映在模型中

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

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