SAPUI5:自定义过滤包含用于来自控制器的动态绑定

问题描述 投票:0回答:1

我想使用自定义过滤包含如下内容: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"))
            });

有人有解决方案吗?

sapui5
1个回答
0
投票

我找到了解决方案:我创建了一个控件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 >
© www.soinside.com 2019 - 2024. All rights reserved.