SAPUI5:自定义过滤包含来自控制器的动态绑定
SAPUI5: Custom filtering contains for a dynamic binding from controller
我想像这里一样使用自定义过滤包含: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 >
我想像这里一样使用自定义过滤包含: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 >