2016-10-04 154 views
0

我正在使用_.findIndex它返回一个数组,它需要被推送到数组。我怎样才能做到这一点?lodash findindex推到一个数组

$scope.filtersRequested[_.findIndex($scope.filtersRequested, { 
'codeColumnName': $scope.refData[idx].codeColumnName 
             })].filterCondition = strWhere; 

回答

0

如果我理解正确,您希望将filterCondition设置为特定值。既然你使用lodash,你最好使用_.set,这是安全的(即,如果第一个参数arg未定义,则不会失败)和_.find(以访问相关请求)。因此,我建议你这样做:

_.set(
_.find($scope.filtersRequested, {'codeColumnName': $scope.refData[idx].codeColumnName}) , 
'filterCondition', strWhere 
); 

如果找到的元素,则_.set将操作就可以了,否则会优雅地忽略它。