Skip to Content
avatar image
Former Member

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 02, 2015 at 01:56 PM

    Hi Asif,

    Try like this:

    var ModelNEW = new sap.ui.model.json.JSONModel();
    ModelNEW.loadData("factoryview.json");
    ModelNEW.attachRequestCompleted(function(){
    sap.ui.getCore().setModel(ModelNEW, "myDataModel");
    var gDataModel = sap.ui.getCore().getModel("myDataModel"); 
    alert(gDataModel.getProperty("/L3_ST70_conveyor"));
    });
    

    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded