Using mock data in SAPUI5

To use the data in a mock file that is saved locally in the “model” folder you need to loadData from that file as follows:

 

	
onInit: function() {
// set data model on view
//var data = {
//"studentSet": [{
//"name": "Kareem",
//"class": "KG1",
//"Nationality": "Palestinian"
//}, {
//"name": "Ahmad",
//"class": "KG3",
//"Nationality": "Saudi"
//}]
//};
//var oModel = new JSONModel();
//oModel.setData(data);


var oModel = new JSONModel();
// Load JSON in from the file
oModel.loadData("model/myData.json");

this.getView().setModel(oModel);

},

 

Leave a Comment.