[英]SAPUI5 adding Data to JSON Model from Local Storage
I need to add something from my local Storage to my JSONModel that I can use it in a view.xml. 我需要将本地存储中的某些内容添加到JSONModel中,以便可以在view.xml中使用它。
In my function where I build up the JSON Model I read the data I need from the local storage. 在构建JSON模型的函数中,我从本地存储读取了我需要的数据。
de.fum.nmp.util.Storage.getItem("amountSync").done(function(amountSync) {
amountSync = JSON.stringify(amountSync);
}).fail(function() {
var i = 0;
});
de.fum.nmp.util.Storage.getItem("newSyncTime").done(function(sSyncime) {
aSyncTimes = JSON.stringify(sSyncime);
}).fail(function(sError) {
var i = 0;
});
These two deliver the two data fields I need. 这两个提供了我需要的两个数据字段。 After that the JSON Model is build, but that already happened before I implemented the reading from the storage.
之后,构建了JSON模型,但是在实现从存储中读取之前已经发生了。
var oModel = new sap.ui.model.json.JSONModel(oData);
this.getView().setModel(oModel);
How can I make sure that I add those data to the JSON Model, too? 如何确保也将这些数据添加到JSON模型?
You can do this by setting the property value of the model with the data extracted from localStorage. 您可以通过使用从localStorage提取的数据设置模型的属性值来完成此操作。
Ex: this.getView().getModel().setProperty("/amountSync", amountSync );
Bind the amountSync model property to the control. 将amountSync模型属性绑定到控件。
var view = this;
de.fum.nmp.util.Storage.getItem("amountSync").done(function(amountSync) {
amountSync = JSON.stringify(amountSync);
view.getView().getModel().setProperty("/amountSync", amountSync );
}).fail(function() {
var i = 0;
});
de.fum.nmp.util.Storage.getItem("newSyncTime").done(function(sSyncime) {
aSyncTimes = JSON.stringify(sSyncime);
view.getView().getModel().setProperty("/aSyncTimes ", aSyncTimes );
}).fail(function(sError) {
var i = 0;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.