我有问题是无法按日期对数据进行排序
这是我的输出
[ { text: '3',
id: '1',
device: 'I',
name: 'Vishal',
createdAt: '2018-12-03T11:10:19.287Z' },
{ text: '1',
id: '1',
device: 'I',
name: 'Vishal',
createdAt: '2018-12-03T11:02:14.621Z' },
{ text: '2',
id: '2',
device: 'A',
name: 'Vishal',
createdAt: '2018-12-03T11:02:20.669Z' } ]
实际输出在这里...
[ { text: '1',
id: '1',
device: 'I',
name: 'Vishal',
createdAt: '2018-12-03T11:02:14.621Z' },
{ text: '2',
id: '2',
device: 'A',
name: 'Vishal',
createdAt: '2018-12-03T11:02:20.669Z' },
{ text: '3',
id: '1',
device: 'I',
name: 'Vishal',
createdAt: '2018-12-03T11:10:19.287Z' } ]
答案 0 :(得分:0)
添加此库
"underscore": "^1.9.1"
import _ from 'underscore';
let temp = _.sortBy(items, 'createdAt');
console.log('Results....',temp);
输出
[ { text: '1',
id: '1',
device: 'I',
name: 'Vishal',
createdAt: '2018-12-03T11:02:14.621Z' },
{ text: '2',
id: '2',
device: 'A',
name: 'Vishal',
createdAt: '2018-12-03T11:02:20.669Z' },
{ text: '3',
id: '1',
device: 'I',
name: 'Vishal',
createdAt: '2018-12-03T11:10:19.287Z' } ]