我试图按“名称”值对数组进行排序(使用Lodash)。我使用Lodash文档在下面创建了解决方案,但是.orderBy似乎根本没有任何影响。任何人都可以阐明对数组进行排序的正确方法吗?
字符数组
[
{
"id":25,
"name":"Anakin Skywalker",
"createdAt":"2017-04-12T12:48:55.000Z",
"updatedAt":"2017-04-12T12:48:55.000Z"
},
{
"id":1,
"name":"Luke Skywalker",
"createdAt":"2017-04-12T11:25:03.000Z",
"updatedAt":"2017-04-12T11:25:03.000Z"
}
]
功能码
var chars = this.state.characters;
_.orderBy(chars, 'name', 'asc'); // Use Lodash to sort array by 'name'
this.setState({characters: chars})