lodash 中 remove

 var obj = {
        "objectiveDetailId": 285,
        "objectiveId": 29,
        "number": 1,
        "text": "x",
        "subTopics": [{
            "subTopicId": 1,
            "number": 1
        }, {
            "subTopicId": 2,
            "number": 32
        }, {
            "subTopicId": 3,
            "number": 22
        }]
    }
    var stToDelete = 2;

        _.remove(obj.subTopics, function(item, index, models) {
      
            return item.subTopicId === stToDelete;
        });
        _.remove(obj.subTopics, {
            subTopicId: stToDelete
        });

  item:当前循环项

      index:当前索引值

      modes:循环的数组

 

posted @ 2017-12-22 09:45  山顶洞外人  阅读(3199)  评论(0编辑  收藏  举报