cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass array object to 'items' to sap.ui.commons.DropdownBox in SAPUI5

VenkyM
Participant
0 Kudos

Hi ,

I am trying to pass array of values to sap.ui.commons.DropdownBox options in SAPUI5 but entire object is displaying in dropdown box.

Below is the code,

dropDownBox: function(dropDownLabel,dropDownItems){

  var dropDownOptions = {dept1:"Dept1",dept2:"Dept2"};

  var dropDownElement = new sap.ui.layout.form.FormElement({

  label : new sap.ui.commons.Label({

  text : dropDownLabel

  }),

  fields : [ new sap.ui.commons.DropdownBox("Depts", {

  layoutData : new sap.ui.layout.form.GridElementData({

  hCells : "3"

  }),

  items : [new sap.ui.core.ListItem("Deptlist", {

  text : dropDownOptions

  }) ]

  }) ]

  });

return dropDownElement;

}

Output:

Please help me .

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Venkatesh,

Check this -


var dropDownOptions = [{dept1:"Dept1",dept2:"Dept2"},{dept1:"Dept11",dept2:"Dept21"}]; //Consider you have an array like this

sap.ui.getCore().getModel().setProperty("/dropDownOptions",dropDownOptions); //Bind the dropDownOptions array to a model

var oItemTemplate = new sap.ui.core.ListItem({text:"{dept1}"});

var oDDBox = new sap.ui.commons.DropdownBox({

    items: {

  path: "/dropDownOptions",

  template: oItemTemplate

  }

});

Regards,

Sai Vellanki.

Answers (2)

Answers (2)

former_member182862
Active Contributor
0 Kudos

HI Venkatesh

There are 2 ways to do this.

1. http://jsbin.com/bavoja/edit?js,output (use model like about Santhosh has suggested)

2. http://jsbin.com/tonemu/edit?js,output (use model - assuming that your data come in as a map, you need to convert it to array)

Hope this helps

Thanks

-D

santhu_gowdaz
Active Contributor
0 Kudos

  items : [new sap.ui.core.ListItem("Deptlist", {

text:'{dept1}',


and bind dropdown items with"dropDownOptions ".


Edit fiddle - JSFiddle