我试图对一个基于多个属性的对象数组进行排序。即,如果第一个属性在两个对象之间是相同的,那么应该使用第二个属性来比较两个对象。例如,考虑以下数组:
var patients = [
[{name: 'John', roomNumber: 1, bedNumber: 1}],
[{name: 'Lisa', roomNumber: 1, bedNumber: 2}],
[{name: 'Chris', roomNumber: 2, bedNumber: 1}],
[{name: 'Omar', roomNumber: 3, bedNumber: 1}]
];
Sorting these by the roomNumber
attribute i would use the following code:
var sortedArray = _.sortBy(patients, function(patient) {
return patient[0].roomNumber;
});
This works fine, but how do i proceed so that 'John' and 'Lisa' will be sorted properly?