我正在使用v4.11.0.我想根据milliseconds属性对对象进行排序.这是阵列:
[
{
"name": "bug12755.xml",
"list": "bugs42",
"start-date": "2015-09-14",
"age": {
"text": "7 months",
"milliseconds": 18381227304
}
},
{
"name": "bug12922.xml",
"list": "bugs42",
"start-date": "2015-08-27",
"age": {
"text": "8 months",
"milliseconds": 19936427304
}
},
{
"name": "bug13183.xml",
"list": "bugs50",
"start-date": "2015-08-27",
"age": {
"text": "8 months",
"milliseconds": 19936427305
}
}
]
Run Code Online (Sandbox Code Playgroud)
我遗漏了一些关于这个iteratee功能的基本知识.我有这个,但似乎没有排序数组.提前致谢!
_.orderBy(list, function(item) {
return item.age.value;
}, ['desc']);
Run Code Online (Sandbox Code Playgroud)
Jes*_*oco 28
您似乎是在酒店订购value.
u.orderBy(list, function(e) { return e.age.milliseconds}, ['desc']);
Run Code Online (Sandbox Code Playgroud)
小智 19
https://codepen.io/a2qube/pen/pKYrgN
关于如何使用Lodash的简单示例:orderBy基于内部属性进行排序.
hotels = _.orderBy(hotels, 'account.id', 'desc');