简体   繁体   English

JSONModel 相互比较模型

[英]JSONModel Compare Models with each other

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. Sergio 找到了这个提示,但没有样本。 https://archive.sap.com/discussions/thread/3667904 https://archive.sap.com/discussions/thread/3667904

Would be nice if someone of you could help me with a nice solution.如果你们中有人能帮我找到一个很好的解决方案,那就太好了。

Thanks, Dirk谢谢,德克

As you are using JSONModels, extract each model's data using the getJSON method and then transform them into JS objects.当您使用 JSONModels 时,使用 getJSON 方法提取每个模型的数据,然后将它们转换为 JS 对象。

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? 如何确定两个 JavaScript 对象的相等性?

jQuery object equality jQuery 对象相等

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

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