使用“$filter”后选择当前数组项,查看它是否在其中

Select current Array item after using `$filter` to see if it is even there

本文关键字:在其中 是否 数组 filter 选择 使用      更新时间:2023-09-26

我有一个存储过程,它返回一个逗号分隔的数字列表。我把它和split放进array

然后,使用angular.forEach(),我需要在数组(scope.dataForStoreHierachy)中搜索和具有匹配编号的id。

var found = $filter('filter')(scope.dataForStoreHierachy, { id: parseInt(current) }, true);

这很好,但有没有办法隔离数组中的特定项,以查找元素的其他属性?

为了得到奇异元素,我使用了下面的代码

$filter('filter')(scope.dataForStoreHierachy, function (d) { return d.id === parseInt(current); })[0]