如何使用 ComboBox 过滤 table?

How can I filter through a table using a ComboBox?

我唯一需要知道的是,如果我可以为 ComboBox 中的项目创建一个值,那么我认为我将能够完成手头的任务。我会做类似的事情吗:

var oItem1 = new sap.ui.core.ListItem("lab", {
    text: 'Lab',
    value: 'Lab'
});

var oItem2 = new sap.ui.core.ListItem("boxer", {
    text: 'Boxer',
    value: 'Boxer'
});

然后我会使用一个按钮来过滤 table,如下所示:

var oButton = new sap.ui.commons.Button({
    text: "find",
    styled: false,
    press: function () {
        var oFilter1 = new sap.ui.model.Filter("typeOfDog", sap.ui.model.FilterOperator.Contains, oItem1.getValue());
        var oFilter2 = new sap.ui.model.Filter("typeOfDog", sap.ui.model.FilterOperator.Contains, oItem2.getValue());
        var allFilter = new sap.ui.model.Filter([oFilter1, oFilter2], false);
        oTable.getBinding("rows").filter(allFilter);
    }
}).addStyleClass("searchButton").placeAt("search");

然而,这不起作用。我假设这是因为我无法为 ListItem 创建值。如果可以,我该怎么做?

编辑:有没有办法做类似 CheckBox 的事情,一个等价于 .getChecked() 的方法?

我明白了。我改用了 DropdownBox 并使用了以下代码:

oDropDown.attachChange(function () { oTable.getBinding("rows").filter(new sap.ui.model.Filter("payment", sap.ui.model.FilterOperator.EQ, oDropDown.getValue())); });

我认为您也可以使用 FacetFilters。FacetFilter 由 FacetFilterList 组成,这些是 table.Based 中的列,在 facetfilter table 中选择的值将被过滤。