cancel
Showing results for 
Search instead for 
Did you mean: 

local json file vs data maintained in controller

prasad
Participant
0 Kudos

Hi all

This is my code in controller init method

mycontroller = this

var data =

[

{"No":"456980",

"Updates":[{ "Test": "abc"}, {"Test": "bca"},{"Test": "dbd"}] },

{"No":"456980",

"Updates":[{ "Test": "abc"}, {"Test": "bca"},{"Test": "dbd"}] },

{"No":"456980",

"Updates":[{ "Test": "abc"}, {"Test": "bca"},{"Test": "dbd"}] }

]   

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

oModel.setData(data);

//set this model to list control having custom list as aggregation

mycontroller.List1.setModel(oModel);

mycontroller.List1.bindAggregation("items",{path:"/",template:mycontroller.List1_template});

var ListItems = P1Notificationcontroller.P1ticket.getItems();

var ListLength = ListItems.length;

for(var i=0; i<ListLength; i++){

var control = "status_vbox-list1-"+i;

sap.ui.getCore().byId(control).bindAggregation("items",{path:"Updates",template:new sap.m.Text('',{text:'{Update}'})});

}

view declaration create content

oController.List1 = new sap.m.List("list1",{headerDesign : sap.m.ListHeaderDesign.Standard});

oController.List1_template = new sap.m.CustomListItem("McustomlistItem",{content : [

new sap.m.VBox('',{items:

  [

             new sap.m.Text('',{text:"{No}"})

            new sap.m.VBox('status_vbox',{items:[]})

  ]

  }));

  

  

The above code in view and controllers init method works perfectly fine the items in custom list vbox are aggregated from update array in data

when the same data when maintained in local  json file &

by using this line of code

var jsonmodel = new sap.ui.model.json.JSONModel("mockData/local.json");

mycontroller.List1.setModel(jsonmodel)

the loop for vbox is failing because we are not able to loop the object .

when i console.log of both models odata attribute of one model is showing as Array and other as object , because of object the loop is not happening

how can we maintain the same data in local json file to loop the updates attribute to the vbox in custom list item as above.


Thanks

Prasad

Accepted Solutions (1)

Accepted Solutions (1)

prasad
Participant
0 Kudos

issue resolved by using the below code   jQuery.ajax({             url: "mockData/Local.json",             dataType: "json",             success: function(data, textStatus, jqXHR) {                    var jsonmodel = new sap.ui.model.json.JSONModel();                 jsonmodel.setData(data);                 sap.ui.getCore().setModel(jsonmodel,'testmodel');             mycontroller.List1.setModel(jsonmodel)               }

Answers (0)