基于外部数组的Lodash排序集合 [英] Lodash sort collection based on external array
本文介绍了基于外部数组的Lodash排序集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的键的数组:
I have an array with keys like so:
['asdf12','39342aa','12399','129asg',...]
以及在每个对象中都有这些键的集合,如下所示: / p>
and a collection which has these keys in each object like so:
[{guid: '39342aa', name: 'John'},{guid: '129asg', name: 'Mary'}, ... ]
是否有一种快速的方法可以根据键的顺序对集合进行排序在第一个数组中?
Is there a fast way to sort the collection based on the order of keys in the first array?
推荐答案
var sortedCollection = _.sortBy(collection, function(item){
return firstArray.indexOf(item.guid)
});
这篇关于基于外部数组的Lodash排序集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文