【发布时间】:2016-12-29 23:20:05
【问题描述】:
我的表中有多个列,例如:
id | name | amount | description
我想对每一列进行排序 - 第一次单击时按升序排列,第二次按降序排列,第三次返回默认值,然后从头再来。
默认是按升序排列的id 列。
所以,reducer 中的默认状态是:
sort: {
key: 'id',
desc: false
}
单击名称列的下一步是:
sort: {
key: 'name',
desc: false
}
sort: {
key: 'name',
desc: true
}
sort: {
key: 'id',
desc: false
}
视图使用列名作为参数调用操作:
<td onClick={() => this.props.sort('name')}>Name</td>
<td onClick={() => this.props.sort('amount')}>Amount</td>
一个动作应该调度这样的key 和desc 值,以便它匹配我的模式:
export function sort(key) {
return dispatch => {
};
};
我该怎么做?
【问题讨论】: