按 Asc 和 Desc 日期排序
Sorting By Asc and Desc date
尝试按给定的日期按 desc 和/或 asc 对我的不可变列表进行排序,但它并不是真正有效,在对单词进行排序时它工作正常但不是列表中的以下日期。使用反应虚拟化的递减和递增值。如果有人能告诉我如何最好地解决这个问题,将会很有帮助。或者如果没有,还有什么其他选择?
import { List } from 'immutable';
import * as React from 'react';
import { SortDirection } from 'react-virtualized';
class TopComp extends React.Component {
constructor(props) {
super(props);
const data = List([
{
0: {
'Date Reported': 'Mar 16, 2015',
}
},
{
0: {
'Date Reported': 'Mar 16, 2015',
}
},
{
0: {
'Date Reported': 'Mar 02, 2015',
}
},
{
0: {
'Date Reported': 'Mar 02, 2015',
}
},
{
0: {
'Date Reported': 'Feb 23, 2015',
}
},
{
0: {
'Date Reported': 'Feb 23, 2015',
}
},
{
0: {
'Date Reported': 'Oct 07, 2014',
}
},
{
0: {
'Date Reported': 'May 30, 2014',
}
},
]);
this.state = {
data,
};
}
render() {
const { data } = this.state;
let t = null;
t = data.sortBy(item => item[0]['Date Reported']).update((t) => {
console.log(t);
const Direction = SortDirection.DESC;
return (Direction === SortDirection.DESC ? t.reverse() : t);
});
console.log(t.toJS());
return (
<div>
<span>Hey</span>
</div>
);
}
}
export default TopComp;
真的不明白为什么有些约会会如期而至?
你的日期排序不正确,因为最重要的部分(年份)在字符串的末尾,排序会将它们视为最不重要的部分,因此你的问题。
如果您可以通过不同的方式获取数据(我希望您可以),请向数据添加另一个元素,它可以是时间戳或 ISO 日期字符串,它们将正确排序。
const data = List([
{
0: {
'Date Reported': 'Mar 16, 2015',
'isodate': "2015-03-16T03:30:49.566+0000"
}
},
尝试按给定的日期按 desc 和/或 asc 对我的不可变列表进行排序,但它并不是真正有效,在对单词进行排序时它工作正常但不是列表中的以下日期。使用反应虚拟化的递减和递增值。如果有人能告诉我如何最好地解决这个问题,将会很有帮助。或者如果没有,还有什么其他选择?
import { List } from 'immutable';
import * as React from 'react';
import { SortDirection } from 'react-virtualized';
class TopComp extends React.Component {
constructor(props) {
super(props);
const data = List([
{
0: {
'Date Reported': 'Mar 16, 2015',
}
},
{
0: {
'Date Reported': 'Mar 16, 2015',
}
},
{
0: {
'Date Reported': 'Mar 02, 2015',
}
},
{
0: {
'Date Reported': 'Mar 02, 2015',
}
},
{
0: {
'Date Reported': 'Feb 23, 2015',
}
},
{
0: {
'Date Reported': 'Feb 23, 2015',
}
},
{
0: {
'Date Reported': 'Oct 07, 2014',
}
},
{
0: {
'Date Reported': 'May 30, 2014',
}
},
]);
this.state = {
data,
};
}
render() {
const { data } = this.state;
let t = null;
t = data.sortBy(item => item[0]['Date Reported']).update((t) => {
console.log(t);
const Direction = SortDirection.DESC;
return (Direction === SortDirection.DESC ? t.reverse() : t);
});
console.log(t.toJS());
return (
<div>
<span>Hey</span>
</div>
);
}
}
export default TopComp;
真的不明白为什么有些约会会如期而至?
你的日期排序不正确,因为最重要的部分(年份)在字符串的末尾,排序会将它们视为最不重要的部分,因此你的问题。
如果您可以通过不同的方式获取数据(我希望您可以),请向数据添加另一个元素,它可以是时间戳或 ISO 日期字符串,它们将正确排序。
const data = List([
{
0: {
'Date Reported': 'Mar 16, 2015',
'isodate': "2015-03-16T03:30:49.566+0000"
}
},