问题
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