相关疑难解决方法(0)

使用Lodash按值排序对象数组

我试图通过'name'值对数组进行排序(使用Lodash).我使用Lodash文档创建了下面的解决方案.然而,orderBy似乎没有任何影响.任何人都可以对排序数组的正确方法有所了解吗?

Chars Array

[  
   {  
      "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"
   }
]
Run Code Online (Sandbox Code Playgroud)

功能代码

 var chars = this.state.characters;

 chars = _.orderBy(chars, 'name', 'asc'); // Use Lodash to sort array by 'name'

 this.setState({characters: chars})
Run Code Online (Sandbox Code Playgroud)

arrays lodash

66
推荐指数
3
解决办法
11万
查看次数

标签 统计

arrays ×1

lodash ×1