简体   繁体   English

如何过滤剑道网格(AngularJs)中的对象数组?

[英]How to filter an array of objects in Kendo Grid (AngularJs)?

I have a Document object like this:我有一个文件 object 是这样的:

{"id": 1, "annotation": "some text", "signers": [{ "id": 32, "name": "Bob", "address": {"country": "USA"}}, 
{ "id": 44, "name": "Bill", "address": {"country": "Canada"}}]}

Documents are displayed in a Kendo grid, and one of the columns is for signers.文档显示在 Kendo 网格中,其中一列用于签名者。 How is it possible to filter signers by name (and also by country, but that is less relevant)?如何按姓名(也可以按国家/地区,但这不太相关)过滤签名者? How to filter an array of objects?如何过滤对象数组?

I've been trying to figure out how to write a custom filter function and do all the filtering on client side, but I haven't been able to figure this out.我一直在试图弄清楚如何编写自定义filter function 并在客户端进行所有过滤,但我无法弄清楚这一点。

You can create a Set of the names or countries to search for and call Set#has in the callback for Array#filter .您可以创建一Set名称或国家来搜索并在Array#filter的回调中调用Set#has

 let doc = {"id": 1, "annotation": "some text", "signers": [{ "id": 32, "name": "Bob", "address": {"country": "USA"}}, { "id": 44, "name": "Bill", "address": {"country": "Canada"}}]}; const names = new Set(["Bob", "Joe"]); doc.signers = doc.signers.filter(({name})=>names.has(name)); console.log(doc);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM