2015-10-19 77 views
0

我想在我的代碼中使用lodash

我用jQuery,但我想lodash取代 -

我的jQuery代碼:

$scope.annotations = $scope.dashboard.annotations.list; 
var indexes = $.map($scope.annotations, function(obj, index) { 
    if(obj.name === annotation) { 
     return index; 
    } 
}); 
var firstIndex = indexes[0]; 
$scope.annotations.splice(firstIndex, 1); 

我找到匹配對象的索引值。 替換什麼$.map我試過_.map_.filter沒有得到確切的結果。

+0

對我來說似乎像Angular scope元素註釋和下劃線圖方法。您通常不會將jQuery與Angular混合使用,因爲它不被認爲是一種好的做法。無論如何,你似乎不清楚你想要歸檔什麼。也許一些輸入數據,以及你所期望的和你得到的,可以彌補這一點。 – Margus

回答

0

它是正確的嗎?

我的代碼:

$scope.annotations = $scope.dashboard.annotations.list; 
    var index = _.findIndex($scope.annotations, function(obj) { 
    return obj.name === annotation; 
    }); 
    $scope.annotations.splice(index, 1); 

這是工作的罰款..只是想知道邏輯明智的正確與否。