我對與_.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中嘗試了你的代碼,它完美的工作,但不知道我的數組中的每個對象。我會回去檢查,如果它的工作,我會接受你的答案。非常感謝。 –