Javascript 如何使我的搜索变得模糊

Javascript 如何使我的搜索变得模糊,javascript,sapui5,Javascript,Sapui5,我可以使用单个值将特定列表放在顶部。如何使我的搜索变得模糊,以便它接受列表中的odata的任何数据 var sf = new sap.m.SearchField({ placeholder: "Search", showRefreshButton: true, liveChange: function(oEvent) { var tpmla = oEvent.g

我可以使用单个值将特定列表放在顶部。如何使我的搜索变得模糊,以便它接受列表中的
odata
的任何数据

var sf = new sap.m.SearchField({
                        placeholder: "Search",
                        showRefreshButton: true,
                    liveChange: function(oEvent) {
var tpmla = oEvent.getParameter("newValue");
var filters = new Array();
var oFilter = new sap.ui.model.Filter("Kunnr", sap.ui.model.FilterOperator.Contains, tpmla);
                         filters.push(oFilter);
                         this.oList = sap.ui.getCore().byId("po_list");
                         this.oList.getBinding("items").filter(filters);})

我需要了解如何提供更多类型的输入
Name1,Addr.

您可以向
sap.ui.model.ListBinding添加多个过滤器:

var filters = [];
filters.push(new sap.ui.model.Filter("Kunnr", sap.ui.model.FilterOperator.Contains, tpmla));
filters.push(new sap.ui.model.Filter("Name1", sap.ui.model.FilterOperator.Contains, tpmla));
filters.push(new sap.ui.model.Filter("Addr", sap.ui.model.FilterOperator.Contains, tpmla));

this.oList = sap.ui.getCore().byId("po_list");
this.oList.getBinding("items").filter(filters);
据我所知,这将使用AND关系链接不同的过滤器,这意味着只有当所有字段中都包含
tmpla
时,它才会匹配。没有办法让这成为一个OR。解决方法是在模型上创建一个搜索字段,其中包含所有可能作为串联字符串搜索的值


Chris

有关
关系,请检查@cschuff的答案

实际上,您可以使用
新的sap.ui.model.Filter(过滤器,带)定义搜索字段的
关系如果设置了波段,则过滤器内的所有过滤器都将被AND,否则它们将被OR

var filters = [];
filters.push(new sap.ui.model.Filter("Kunnr", sap.ui.model.FilterOperator.Contains, tpmla));
filters.push(new sap.ui.model.Filter("Name1", sap.ui.model.FilterOperator.Contains, tpmla));
filters.push(new sap.ui.model.Filter("Addr", sap.ui.model.FilterOperator.Contains, tpmla));
var orFilters = new sap.ui.model.Filter(filters,false);

this.oList = sap.ui.getCore().byId("po_list");
this.oList.getBinding("items").filter([orFilters]);

嗨,cschuff,实际上你可以为过滤器定义或关系,请看下面我的答案。很好,谢谢你的提示。但在文档中找不到:/您从未停止学习:)