How can I filter a dstore using the contains method?

邮差的信 提交于 2019-12-22 13:48:11

问题


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"]}
]

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.

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

Am I doing something wrong?

Thanks.


回答1:


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

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

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

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

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



来源:https://stackoverflow.com/questions/36904980/how-can-i-filter-a-dstore-using-the-contains-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!