Improve Transfer onChange, close #972

This commit is contained in:
afc163 2016-02-01 14:07:17 +08:00
parent 271aaf29e1
commit 6327220266
3 changed files with 8 additions and 8 deletions

View File

@ -36,7 +36,8 @@ const App = React.createClass({
}
this.setState({ mockData, targetKeys });
},
handleChange(targetKeys) {
handleChange(targetKeys, direction, moveKeys) {
console.log(targetKeys, direction, moveKeys);
this.setState({ targetKeys });
},
renderFooter() {

View File

@ -46,19 +46,18 @@ class Transfer extends Component {
moveTo(direction) {
const { targetKeys } = this.props;
const { leftCheckedKeys, rightCheckedKeys } = this.state;
const moveKeys = direction === 'right' ? leftCheckedKeys : rightCheckedKeys;
// move items to target box
const newTargetKeys = direction === 'right' ?
leftCheckedKeys.concat(targetKeys) :
targetKeys.filter((targetKey) => {
return !rightCheckedKeys.some((checkedKey) => targetKey === checkedKey);
});
const newTargetKeys = direction === 'right'
? moveKeys.concat(targetKeys)
: targetKeys.filter(targetKey => !moveKeys.some(checkedKey => targetKey === checkedKey));
// empty checked keys
this.setState({
[direction === 'right' ? 'leftCheckedKeys' : 'rightCheckedKeys']: [],
});
this.props.onChange(newTargetKeys);
this.props.onChange(newTargetKeys, direction, moveKeys);
}
getGlobalCheckStatus(direction) {

View File

@ -21,7 +21,7 @@
| dataSource | 数据源 | Array | [] |
| render | 每行数据渲染函数 | Function(record) | |
| targetKeys | 显示在右侧框数据的key集合 | Array | [] |
| onChange | 变化时回调函数 | Function(newTargetKeys) | |
| onChange | 变化时回调函数 | Function(targetKeys, direction, moveKeys) | |
| listStyle | 两个穿梭框的自定义样式 | Object | |
| className | 自定义类 | String | |
| titles | 标题集合,顺序从左至右 | Array | ['源列表', '目的列表'] |