【发布时间】:2015-09-14 18:00:47
【问题描述】:
我被要求使用 lodash 的 _.every 更改一些代码:
//for every item in collection, check if "someProp" is true,
//but only if "someProp2" isn't "-1". If "someProp" is true for
//every item in collection, return true.
$scope.areAllTrue = function() {
for(var i=0; i<$scope.collection.length; i++){
if($scope.collection[i].someProp2 === -1) {
continue;
}
if(!$scope.collection[i].someProp) {
return false;
}
}
return true;
};
所以跟着lodashexample的:
_.every(users, 'active', false);
我们得到:
$scope.areAllTrue = function() {
return _.every($scope.collection, 'someProp', true)
};
这处理“对于集合中的每个项目,检查 someProp 是否为真,如果所有都为真,则返回真。”但是我可以以某种方式在这里进行“继续”检查吗?
编辑:我可以以某种方式使用两个谓词和“_.every”吗?喜欢if someProp1 === true || someProp2 === -1?
【问题讨论】:
标签: angularjs for-loop lodash continue