2016-10-04 48 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將操作就可以了,否則會優雅地忽略它。