Skip to Content
0
Mar 06, 2017 at 12:17 PM

Unable to add Items to select in SAP UI5

958 Views Last edit Mar 06, 2017 at 12:18 PM 2 rev

Hi Folks,

I have created a sapui5 application in which i need to generate select items dynamically.

I am fetching sub-departments by using department in function import.

 f {bAllowTextSelection: true, mEventRegistry: Object, sId: "__xmlview1--ab", mProperties: d, mAggregations: Object…}
View1.controller.js?eval:37 Object {__metadata: Object, results: Array[5]}
View1.controller.js?eval:49 HR-Others
View1.controller.js?eval:49 HR-Payroll
View1.controller.js?eval:49 HR-Recruitment
View1.controller.js?eval:49 HR
View1.controller.js?eval:49 Academy

As you can see my function import is working successfully, for 'HR' department am getting corresponding sub-departments.

Now what i have done in my view for sub-departments -

<Label text="Select Sub-Department" required="true" />

     <Select width="60%" id="ab"></Select>

And here is my controller -

   var odata1 =
   {
   'Department':selected_dep
   };
    var select_sub = this.getView().byId("ab");
    console.log(select_sub);
  oModel.callFunction('/SubDpByDp',"GET",odata1,null,function(oData,response)
   {
   console.log(oData);
   MessageToast.show("success");
   for(var set of oData.results)
  {
var item = new sap.ui.core.Item();
   item.text= set.SUBDEPARTMENT;
   console.log(item.text);
 select_sub.addItem(item);
   }
    },function(err){
   MessageToast.show("faliure");
     },false
     );

But still select is populating nothing.

Kindly suggest.

Regards,

Ankit

Attachments

capture.jpg (13.5 kB)