Skip to Content
0

Multicombox is not displaying tokens when value is selected from it.

May 15 at 12:10 PM

19

avatar image

Hi all,

I have one array of data and I want to bind that data to multicombobox.

I have binded that data to Multicombobox using javascript as shown below.

The problem is when I select any value from multicombobox, tokens are not displaying as per the default behavior of the control.

Please help me in this. As per my guess, this array is not associative array (do not have keys and values.) this might have caused this issue.


Array:
{  
   "A":"Apple",
   "B":[  
      {  
         "key":1,
        "value":"ball",
         "fruits":[  
            "Apple",
            "Orange",
            "banana",
            "Guava"
            
         ]
      }
     
   ]
}

XML view:
<MultiComboBox id="MCBId" width="280px" class="sapUiTinyMarginTop" ></MultiComboBox>

Controller code:
var data = sap.ui.getCore().getModel("myModel").getData();
       var oModel = new sap.ui.model.json.JSONModel();
        oModel.setData(data);
        this.getView().setModel(oModel, "myModel");

       var fruitsArray = data.fruits[0].names;
        for(var i = 0; i<fruitsArray.length; i++){
           var fruitsDD;
            if(!fruitsDD){
           fruitsDD = this.getView().byId("MCBId");
              }         				
          var oCoreItem = new sap.ui.core.Item();
              oCoreItem.setText(fruitsArray[i]);
               oCoreItem.setKey(fruitsArray[i]);
                 fruitsDD.addItem(oCoreItem);
           }


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers