SAPUI5:如何过滤具有 2 个或更多值的数据 [英] SAPUI5: How to filter data with 2 or more values
问题描述
我目前正在/在 SAPUI5 中尝试一些东西,我已经实现了一个非常简单的搜索,如下所示:
I'm currently trying some stuff with/in SAPUI5 and I've implemented a very simple search like this:
var filters = [];
var query = evt.getParameter("query");
if (query && query.length > 0) {
var nameFilter = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, query);
filters.push(nameFilter);
}
var list = this.getView().byId("list");
var binding = list.getBinding("items");
binding.filter(filters);
现在我有以下问题:通过这个逻辑,我可以按人名搜索或过滤.我还有一些额外的字段,如年龄、性别等,我也想搜索年龄或性别.所以我尝试创建第二个过滤器,比如genderFilter",它使用gender"字段.在此之后,使用 .push() 方法将第二个过滤器添加到过滤器 [].. 但这不起作用.
Now I have following issue: with this logic I can just search, or rather filter, by the name of a person. I've also some additional fields like age, gender, etc and I want to perform a search for the age or gender, too. So I've tried to create a 2nd filter, like "genderFilter", which is using the "gender" field. After this adding this 2nd filter with the .push() method to the filters[]..but this isn't working.
我已经尝试观看文档,观看不同的示例,尝试不同的方法 - 但我很无助.请有人帮我解决这个问题吗?
I've already tried to watch the documentation, watched different examples, tried different ways - but I'm helpless. Can please someone help me with this issue?
推荐答案
对于要求,此代码将起作用.
For the requirement this code will work.
var list = this.getView().byId("list");
var binding = list.getBinding("items");
if( !query ) {
binding.filter( [] );
}
else {
binding.filter( [ new sap.ui.model.Filter([
new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, query ),
new sap.ui.model.Filter("gender", sap.ui.model.FilterOperator.Contains, query )
],false)
]
这篇关于SAPUI5:如何过滤具有 2 个或更多值的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!