Disable item inside combo box SAPUI5

ⅰ亾dé卋堺 提交于 2021-01-28 09:32:08

问题


I have a combo box with, let's say, 2 items.

one of the items has relevant data to report, and the other doesn't.

How would I grey out the unwanted item in the combo box?

I can grey out the entire combo box, but I'm not sure how to grey out items inside a combo box (this combo box is populated by an ODATA call).


回答1:


You can set the items of the combo box to the disabled as follows:

Want to disable the selected item from combo box list:

this.getView().byId("idOfYourComboBox").getSelectedItem().setEnabled(false);

Based on the index of the items in the list.

this.getView().byId("idOfYourComboBox").getItems()[1].setEnabled(false);

Also, you can do the same thing based on the key like:

this.getView().byId("idOfYourComboBox").getItemByKey("keyName")

Let me know if this helps.




回答2:


You can use the property enabled of sap.ui.core.Item. Updated your oData and add one more boolean property like isRelevant which tell which item is enabled/disabled.

XML View

<ComboBox items="{path: '/YourBindingPath'}">
  <core:Item key="{key}" text="{text}" enabled="{enabledProperty}" />
</ComboBox>

JS view

var oItemTemplate = new sap.ui.core.ListItem({
  key: "{key}", 
  text: "{text}", 
  enabled: "{enabledProperty}"
});
var oComboBox = new sap.m.ComboBox({
  items: { 
    path: "/YourBindingPath", 
    template: oItemTemplate 
  }
});


来源:https://stackoverflow.com/questions/52937113/disable-item-inside-combo-box-sapui5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!