我对与_.sortBy(underscore.js)排序值。而 一些问题,我有一些像这样的文本值混合数字:如何排序与underscore.js
[
{
first: A,
second: 10,
third: D3
}
{
first: B,
second: 2,
third: F3
}
{
first: C,
second: 3,
third: G4
}
{
first: A,
second: 9,
third: G5
}
]
我尝试用它进行排序:
var sortedArray = _.sortBy(list_data, function(data) {
return [data[0].first, data[0].second.join("_");
});
它总是返回[{first:A,second:10,third:D3}, {first:A,second:9,third:G6}, {first:B,second:2,third:F3}, {first:C,second:3,third:G4}]
,但我想它返回这样[{first:A,second:9,third:G6}, {first:A,second:10,third:D3}, {first:B,second:2,third:F3}, {first:C,second:3,third:G4}]
我该怎么办? pleace的帮助,我是这个新手。非常感谢你。
我已经在JS Bin中尝试了你的代码,它完美的工作,但不知道我的数组中的每个对象。我会回去检查,如果它的工作,我会接受你的答案。非常感谢。 –