我想使用自定义过滤包含如下内容:https://sapui5.hana.ondemand.com/#/entity/sap.m.ComboBox/sample/sap.m.sample.ComboBoxFilteringContains但是问题是oLocation.setFilterFunction不是一个函数:(项目没有定义到组合框中:
<ComboBox id="my-id" selectionChange='onChange'>
<core:Item key="{key}" text="{text}" />
</ComboBox>
因为它们是在控制器中定义的:
oLocation.bindItems({
path: "backEnd>/Prod(Id1='" + Subid+ "',cat='" + vBpId +
"',ApplicationKey='"/ProductSet",
filters: [
Filter
],
template: new Item({
key: '{backEnd>Id}',
text: '{backEnd>Description}',
customData: [{
Type: "sap.ui.core.CustomData",
key: "Other",
value: '{backEnd>Other}'
}]
}),
/*etc.*/
}).setFilterFunction(function(sTerm, oItem) {
return oItem.getText().match(new RegExp(sTerm, "i"))
});
有人有解决方案吗?
我找到了解决方案:我创建了一个控件ComboBoxContain,它重写ComboBox filterItems如下:
ComboBox.prototype.filterItems = function(mOptions, aItems) {
var sProperty = mOptions.property,
sValue = mOptions.value,
bEmptyValue = sValue === "",
bMatch = false,
sMutator = "get" + sProperty.charAt(0).toUpperCase() + sProperty.slice(1),
aFilteredItems = [],
oItem = null;
aItems = aItems || this.getItems();
if (!bEmptyValue) {
for (var i = 0; i < aItems.length; i++) {
oItem = aItems[i];
// the item match with the value
bMatch = (oItem[sMutator]().match(new RegExp(sValue, "i")) !== null);
if (bMatch) {
aFilteredItems.push(oItem);
}
this._setItemVisibility(oItem, bMatch);
}
}
return aFilteredItems;
};
然后是我的观点:
<cbc:ComboBoxContain id="my-id" selectionChange='onChange'>
<core:Item key="{key}" text="{text}" />
</cbc:ComboBoxContain >