on 06-25-2015 5:32 AM
Hello Experts,
I am not able to read the JSON data which is coming from server and I would like to store one value into local variable? It is working fine if I bind the same model to UI controller ,the data is displaying correctly.But I need store one value into local variable.
Here is my code:
var oModelData = new sap.ui.model.json.JSONModel();
var root = window.location.protocol + '//' + window.location.host;
var url = root + "/idmrest/v72alpha/entries/0";
oModelData.loadData(url);
this.getView().setModel(oModelData, "model1");
var zkey = this.getView().getModel("model1").getProperty("/ENTRIES/MSKEYVALUE/VALUE");
and It is saying "undefined" and if I use:
var zkey = oModelData.getProperty("/ENTRIES/MSKEYVALUE/VALUE");
here also it is undefined
can any body please suggest me here? and also how do we get the array and loop it which is inside the JSON (model1)?
Regards,
Kiran
oModelData.attachRequestCompleted(function() {
var zkey = oModelData.getProperty("/ENTRIES/MSKEYVALUE/VALUE");
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello ,
Thanks.
can you please explain me bit more. how can I do this in my case?
var oModelData = new sap.ui.model.json.JSONModel();
var root = window.location.protocol + '//' + window.location.host;
var url = root + "/idmrest/v72alpha/entries/0";
oModelData.loadData(url);
this.getView().setModel(oModelData, "model1");
oModelData.attachRequestCompleted(function() {
var zkey = oModelData.getProperty("/ENTRIES/MSKEYVALUE/VALUE");
});
Now I need to get Zkey as available globally..
regards,
Kiran
var url = root + "/idmrest/v72alpha/entries/0";
oModelData.loadData(url);
var aData = oModel1.getProperty("/d/results"); //If it is having single data then,("/d"). Debug it you will come to know.
var zkey = aData.MSKEYVALUE;//for single data
for (var i = 0; i < aData.length; i++)
{
console.log(aData[i].MSKEYVALUE);//for multiple data.
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe that you need to wait for the response from the server. try this
oModelData.attachRequestCompleted(function() {
this.getProperty("/ENTRIES/MSKEYVALUE/VALUE");
});
thanks
-D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you put it in a global model? like this
oModelData.attachRequestCompleted(function() {
var m = new sap.ui.model.json.JSONModel({
zkey: this.getProperty("/ENTRIES/MSKEYVALUE/VALUE")
});
sap.ui.getCore().setModel(m, 'global');
});
In future, you can get it this way.
sap.ui.getCore().getModel('global').getProperty('/zkey');
-D
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.