admin管理员组文章数量:1415100
Does Ember have a .difference function like underscore does? I have an ArrayController
with a set of objects in each one. I want to subtract all the objects in ArrayController2
from ArrayController1
:
ArrayController1:
1
2
3
4
ArrayController2:
2
4
Then do the difference:
ArrayController1.difference(ArrayController2) => 1
3
Does Ember have a .difference function like underscore does? I have an ArrayController
with a set of objects in each one. I want to subtract all the objects in ArrayController2
from ArrayController1
:
ArrayController1:
1
2
3
4
ArrayController2:
2
4
Then do the difference:
ArrayController1.difference(ArrayController2) => 1
3
Share
Improve this question
asked Jan 25, 2013 at 14:11
rickyduckrickyduck
4,08414 gold badges61 silver badges95 bronze badges
2 Answers
Reset to default 7I don't think there is an single method that will do that, but you could write a helper that essentially did the following:
array1.reject((function(item) {
return array2.contains(item);
}), array2);
Just looping through array1 and rejecting anything that returns true for array2.contains().
5 years late but there's a puted function setDiff
which you can use to achieve what you want.
import { setDiff } from '@ember/object/puted';
...
ArrayDifference: setDiff('ArrayController1', 'ArrayController2') // [1, 3]
https://www.emberjs./api/ember/2.18/functions/@ember%2Fobject%2Fputed/setDiff
本文标签: javascriptEmberjs equivalent of differenceStack Overflow
版权声明:本文标题:javascript - Ember.js equivalent of .difference? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745172766a2646075.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论