2015-10-19 78 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); 

这是工作的罚款..只是想知道逻辑明智的正确与否。