自定义过滤包含来自控制器

自定义过滤包含来自控制器

本文介绍了SAPUI5:自定义过滤包含来自控制器的动态绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用自定义过滤包含如下:https://sapui5.hana.ondemand.com/#/entity/sap.m.ComboBox/sample/sap.m.sample.ComboBoxFilteringContains
但问题是 oLocation.setFilterFunction 不是函数 :(
项目未定义到组合框中:

I would like to use a custom filtering contains like here : https://sapui5.hana.ondemand.com/#/entity/sap.m.ComboBox/sample/sap.m.sample.ComboBoxFilteringContains
but problem is oLocation.setFilterFunction is not a function :(
items are not defined into combobox :

<ComboBox id="my-id"  selectionChange='onChange'>
                <core:Item key="{key}" text="{text}" />
</ComboBox>

因为它们是在控制器中定义的:

because they are define in controller :

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 如下:

I find the solution:
I created a control ComboBoxContain which override ComboBox filterItems as follow :

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 >

这篇关于SAPUI5:自定义过滤包含来自控制器的动态绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:11