0

I want to use filterFilter functionality but I want to reuse the arrays of data instead of creating a new array everytime it runs. So returning an array of indexes and then I can, inside my service, return the items associated to the indexes. This way I can create a $watch export on my service, so I can watch on the real items instead of the filters.

I considered copying the angular filterFilter source, but that isn't maintainable in the long run, what could I do?

Context:

I'm writing a form wizard service that applies a schema to the steps (there are many with slightly different object structures each step), that holds an array of objects. filterFilter returns a new array of objects, so when I modify the object inside the service using a "setter", it's not updating the object itself, but a new (?) created object, and that's no use for me

4

1 回答 1

0

Javascript 有 Object.keys(arrayName) 可以做到这一点,但您必须为 IE8 或更低版本添加一个 poly-fill。

var a = ['foo', 'bar'];
Object.keys( a ); //returns ['0','1'];

如果您想在旧版浏览器中使用它,MDN Object.keys 文章有一篇实现文章。

但是,在查看您的问题时,我认为您误读了过滤器过滤器。当您使用此过滤器时,它可能会返回与输入不同的数组,但是该过滤器中的每个对象仍然是对原始对象的引用。因此,编辑任何对象都应该毫无问题地修改原始对象。

希望这可以帮助。

于 2013-04-24T07:16:29.887 回答