Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Model Issue

Hi All,

I have a source code that loads a JSON data from file directly under folder json.

Directory > File > Data:

  - json

      factoryview.json

              {"L3_ST70_conveyor":"GREENP.JPG", "L3_ST70_takt":"green"}

Code:

var ModelNEW = new sap.ui.model.json.JSONModel();


ModelNEW.loadData("factoryview.json");


sap.ui.getCore().setModel(ModelNEW, "myDataModel");

var gDataModel = sap.ui.getCore().getModel("myDataModel");

alert(gDataModel.getProperty("/L3_ST70_conveyor"));

I am not getting value of L3_ST70_Conveyor in alert box. It is saying "undefined"

Please advise.

Former Member
replied

Asif,

This should work, check the sample here: Plunker

var oModel = new sap.ui.model.json.JSONModel();

oModel.loadData("factoryview.json");

oModel.attachRequestCompleted(function(oEvent){

var ModelNEW= oEvent.getSource();

sap.ui.getCore().setModel(ModelNEW, "myDataModel");

var gDataModel = sap.ui.getCore().getModel("myDataModel");

alert(gDataModel.getProperty("/L3_ST70_conveyor"))

})

Regards,

Sai Vellanki.

1 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question