lodash orderBy通过嵌套属性 [英] lodash orderBy on nested property
本文介绍了lodash orderBy通过嵌套属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用v4.11.0
.
我想基于milliseconds
属性对对象进行排序.
这是数组:
I'm using v4.11.0
.
I would like sort objects based on milliseconds
property.
Here's the array :
[
{
"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
}
}
]
我缺少有关iteratee
函数的一些基本知识.我有这个,但似乎不对数组进行排序.预先感谢!
I'm missing something fundamental about the iteratee
function. I have this but does not seem to sort the array. Thanks in advance!
_.orderBy(list, function(item) {
return item.age.value;
}, ['desc']);
推荐答案
似乎您是通过属性value
订购的.
It seems that you are ordering by the property value
.
u.orderBy(list, function(e) { return e.age.milliseconds}, ['desc']);
这篇关于lodash orderBy通过嵌套属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文