我需要通过提供的键对对象数组进行排序。排序必须不区分大小写并使用提供的字母表。例如,让我们看一下如下所示的初始数据:
var notOrdered = [{
date: "11-12-2015",
name: "Tomasz",
age: 50,
products: "FDGS",
rate: 500
}, {
date: "12-11-2015",
name: "Łukasz",
age: 54,
products: "ŁBDGS",
rate: 110
}, {
date: "11-12-2015",
name: "Jan",
age: 24,
products: "ŻDGS",
rate: 1000
}, {
date: "11-12-2015",
name: "Łucja",
age: 18,
products: "AEBDGS",
rate: 50
}];
var keys = ["date", "rate", "name"];
var directions = [true, false, true];
var alphabet = '01234567989aąbcćdeęfghijklłmnńoóprsśtuvwxyzźż'
所以我要找的结果是:
var ordered = [{
date: "11-12-2015",
name: "Łucja",
age: 18,
products: "AEBDGS",
rate: 50
}, {
date: "11-12-2015",
name: "Jan",
age: 24,
products: "ŻDGS",
rate: 50
}, {
date: "11-12-2015",
name: "Tomasz",
age: 50,
products: "FDGS",
rate: 500
}, {
date: "12-11-2015",
name: "Łukasz",
age: 54,
products: "ŁBDGS",
rate: 110
}];
使用lodash的sortByOrder函数var ordered = _.sortByOrder(notOrdered, keys, directions)
负责使用提供的密钥和方向进行排序 - 一个接一个。而且效果很好。我现在需要的是使用提供的字母顺序而不是默认字母顺序,并使比较不区分大小写。
应以默认方式比较所提供的字母表中未列出的所有字符。我不能使用localCompare,因为我需要支持旧的IE和移动浏览器。
问题是:我可以以某种方式使lodash的sortByOrder函数使用自定义字母表,如果是这样,该怎么做?