sapui5 - SAPUI5:自定义过滤包含来自控制器的动态绑定
问题描述
我想使用自定义过滤包含如下: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 >
推荐阅读
- json - 使用正则表达式匹配句点分隔字符串中的最后一个单词
- php - LARAVEL如何隐藏一些关系记录?
- javascript - 如何将 npm 依赖项添加为对等依赖项
- angular - Angular 8如何有条件地应用fa fa图标但优化方式
- java - 如何在spring boot中使用分页对存储库实体进行排序
- python - 以后有没有办法在你的代码中使用你的代码输出结果?
- glsl - 为什么纹理函数不知道?我正在使用处理
- python - 图表没有被清除,而是继续添加到 tkinter 中现有图表的下方
- java - 如何在 ivy 中强制执行 HTTPS?
- python-3.x - 如何解析 eml 文件并提取元数据信息