如何使用contains方法过滤dstore? [英] How can I filter a dstore using the contains method?

查看:68
本文介绍了如何使用contains方法过滤dstore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dgrid,其中填充了dstore普通的旧Memory集合,我正在尝试使用包含过滤器方法进行过滤。商店数据看起来像这样:

I have a dgrid populated with a dstore plain old Memory collection, that I am trying to filter using the 'contains' filter method. The store data looks something like this:

[
    {id:"25", users: ["13", "15"]},
    {id:"347", users: ["13"]},
    {id:"653", "users":["13", "17"]}
]

我要检索给定用户所在位置的所有记录用户数组。根据我的理解,我期望能够设置一个像 new Filter()。contains('users','15'); 这样的过滤器,并将其设置为网格的集合,在此示例中保留一行(id ='25')。但是,我剩下0行。我也尝试过为过滤器提供正则表达式,而不仅仅是值匹配,例如 new Filter()。contains('users',new RegExp('^ 15 $')); 但这不会过滤掉任何行。

I want to retrieve all the records where a given user is in the users array. From my understanding, I was expecting to be able to set up a filter like new Filter().contains('users', '15'); and set that as the collection for the grid, leaving one row (id = '25') in this example. However, I am left with 0 rows. I have also tried providing a regular expression for the filter, instead of just value matching, like new Filter().contains('users', new RegExp('^15$')); however this doesn't filter out any rows.

我正在使用dojo v1.10.4,dgrid v1.0.0和dstore v1.1.1。
这是 JSFiddle 演示了我的问题。

I am using dojo v1.10.4, dgrid v1.0.0 and dstore v1.1.1. Here is a JSFiddle demonstrating my problem.

我做错什么了吗?

谢谢。

推荐答案

您将用户存储为数组,这就是为什么您不能使用

You are storing users as an array, that is why you cannot use

new Filter().contains('users', '15');

如果要使用.contains,则必须像这样使用它:

If you want to use .contains than you will have to use it like this:

new Filter().contains('users', ['15']);

aka您必须通过提供数组而不是字符串来进行检查。

a.k.a you have to check by providing an array, not a string.

这篇关于如何使用contains方法过滤dstore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆