假设我有这种数据......
data = [{ "_id" : "1", "parentId" : "thisPostId", "topLevelId" : "1", "text" : "comment
", }, { "_id" : "2", "parentId" : "1", "topLevelId" : "1", "text" : "reply to comment
", }, { "_id" : "3", "parentId" : "2", "topLevelId" : "1", "text" : "reply to reply to comment
", }, { "_id" : "4", "parentId" : "3", "topLevelId" : "1", "text" : "reply to reply to reply to comment
", }]
我需要删除评论及其所有孩子......
如果注释删除是_id:1
,那么我需要一个数组["1","2","3","4"]
,,,然后我可以运行Coll.remove({_id:{$in:["1","2","3","4"]}}, callback);
如果注释要删除_id:2
,那么我需要一个数组["2","3","4"]
如果注释要删除_id:3
,那么我需要一个数组["3","4"]
如果注释要删除_id:4
,那么我需要一个数组["4"]
我试过这个(不知道)......
_.forEach(data, function(value, key){ _.pluck(_.where(key, { "parentId" : "2" }), '_id'); });
并没有工作......
任何有关javascript/lodash/underscore的帮助将不胜感激,,,
谢谢...