【问题标题】:jquery with lodash $.mapjquery 与 lodash $.map
【发布时间】:2015-10-19 10:37:00
【问题描述】:

我想在我的代码中使用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 没有得到确切的结果。

【问题讨论】:

  • 在我看来像 Angular 范围元素注释和下划线映射方法。您通常不会将 jQuery 与 Angular 混合使用,因为这不是一个好的做法。在任何情况下,似乎都不清楚您要归档什么。也许一些输入数据,你所期望的和你得到的,可以解决这个问题。

标签: jquery lodash


【解决方案1】:

对吗?

我的代码:

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

这很好用。只是想知道逻辑是否正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 2015-07-27
    • 2017-09-05
    • 2015-11-25
    • 2018-06-01
    • 2023-02-24
    • 2014-04-26
    相关资源
    最近更新 更多