I am new to openui5. Can anyone assist me, how to bind the json data into Listbox and dropdownbox controls(In my case, I am using JSView and sap.ui.commons library) in openui5. I am having separate json file in my eclipse and also I have added my code snippet here.
//Create Model
var oModel = new sap.ui.model.json.JSONModel();
oModel.loadData("model/Transaction_State.json");
oTransstlistbx.setModel(oModel);
oTransstlistbx.bindProperty("/state_name");
//Create a instance for ListBox
var oTransstlistbx = new sap.ui.commons.ListBox({
allowMultiSelect: true,
visibleItems: 4,
items: [
new sap.ui.core.ListItem({ text: "sample1" }), //need to bind json data here
new sap.ui.core.ListItem({ text: "sample1" }), //need to bind json data here
new sap.ui.core.ListItem({ text: "sample3" }), //need to bind json data here
]
});
This data is coming from Transaction_State.json
file. I am able to load the JSON data but how can I bind the data to Listbox items? Any help would be greatly appreciated.
See this example https://openui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.ComboBox/preview
if this is the json in JSONmodel (products.json - for example it contains 3 records)
you can initialize the model in the controller of the view
Then map it in your vonponent in the XML-view
where you have to set the path (the directory of the array in your json) and map each property of component that you want valorize https://openui5.hana.ondemand.com/explored.html#/entity/sap.m.ComboBox/properties to a property in the model