简体   繁体   中英

Bind Items to a DropDownBox in OpenUI5

I am trying to bind a Value inside of an Array with Objects to a sap.ui.commons.DropdownBox .

My JSON-structure looks like that:

{
  "forms": [
    {
      "name": "First Object"
    },
    {
      "name": "Second Object"
    }
  ]
}

Now I try to bindItems to my DropdownBox like that:

var oItemTemplate = new sap.ui.core.ListItem();
oItemTemplate.bindProperty("text", "{/name}");

var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
sap.ui.getCore().setModel(oModel);

var oDropDown = new sap.ui.commons.DropdownBox("dropDownBox");

oDropDown.bindItems("/forms", oItemTemplate);

Unfortunately the Items, i am adding/binding to the Dropdown, are empty.

How to properly bind Items in an Array of Objects to a DropdownBox?
JSBIN-Example

Got the answer after a very restfully night :)

This is the working code snippet:

var oItemTemplate = new sap.ui.core.ListItem();
oItemTemplate.bindProperty("text", "name");

var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
sap.ui.getCore().setModel(oModel);

var oDropDown = new sap.ui.commons.DropdownBox("dropDownBox");  
oDropDown.bindItems("/forms", oItemTemplate);

JSBIN-Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM