如何在dstore上应用多个过滤器? [英] How to apply multiple filters on a dstore?
问题描述
比方说,一个 dstore
的记录中包含名字,姓氏和年龄.现在,我要使用名字为"Name1"或Age = 25的记录.如何在 dstore
中执行此操作?如果我做, recordStore.filter({name:'Name1'},{age:25});
然后它将返回名称为"Name1"且Age = 25的记录.
Let's say that a dstore
has records with First name, Last name and Age. Now, I want records with First name as "Name1" OR Age= 25. How can I do this in dstore
?
If I do,
recordStore.filter({name: 'Name1'}, {age: 25});
then it returns the records having name as "Name1" AND Age=25.
另一个问题,在我的 dstore
的记录中,还存在一个数组(包含颜色).我想根据用户选择的颜色过滤结果.我面临的问题是 dstore.filter()
检查该值的完全匹配,但是即使数组中的一个值与所选值都匹配,我也想保留记录.该怎么做?
Another question, in the records of my dstore
, there is an array also (comprising of colours). I want to filter the results based on the colours selected by the user. The problem that I face is that dstore.filter()
checks for the complete matching of the value, but I want to retain the record if even one value in the array matches with the selected value. How to do this?
推荐答案
终于明白了!
Filter
对象,然后将其用作 store
的 filter
方法的参数.
Filter
objects can be created from the store
and then used as arguments to filter
method of the store
.
用于执行两个查询的OR/AND:
For doing OR/ AND of two queries:
recordStoreFilter= new recordStore.Filter()
name1Filter= recordStoreFilter.eq('name': 'Name1')
age25Filter= recordStoreFilter.eq('age', 25)
unionFilter= recordStoreFilter.or(name1Filter, age25Filter)
intersectionFilter= recordStoreFilter.and(name1Filter, age25Filter)
unionData= recordStore.filter(unionFilter)
intersectionData= recordStore.filter(intersectionFilter)
//Set using the following
recordGrid.set('collection', unionData) //or intersectionData
要匹配数组中的一个值:
To match one value from an array:
colorFilter= recordStoreFilter.contains({'color', 'red'})
colorData= recordStore.filter(colorFilter)
//This will give the records that have color red in the array.
有关更多信息,请参见此处.
For more, see here.
这篇关于如何在dstore上应用多个过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!