2
votes

I only want save the data of a Model if something of the properties has changed. Therefore I would like to compare the original and the "changed" properties with each other. Found this hint by Sergio, but without a sample. https://archive.sap.com/discussions/thread/3667904

Would be nice if someone of you could help me with a nice solution.

Thanks, Dirk

1
What do you mean exactly by "save" in "I only want to save the data of a model"? What are you trying to achieve or avoid? - Boghyon Hoffmann
Hi Boghyou, I only want send requests to the backend if it has changed. - user2405095
Is your data actually coming from an OData protocol? - Boghyon Hoffmann
@boghyon: no, ajax call - user2405095

1 Answers

1
votes

As you are using JSONModels, extract each model's data using the getJSON method and then transform them into JS objects.

var oModelA = this.getView().getModel("modelName");
var oModelB = new sap.ui.model.json.JSONModel({
    a: 2
});
var oModelAData = JSON.parse(oModelA.getJSON());
var oModelBData = JSON.parse(oModelB.getJSON());

then, compare them using any way avaiable here that suits you

How to determine equality for two JavaScript objects?

jQuery object equality