Transfer Datasource 和 CheckedKeys 逻辑修改 (#1590)

*  Transfer Datasource 和 CheckedKeys 逻辑修改

 + close #1587
 + 当 Transfer 的 Datasource 变化时,会移除组件的 CheckedKeys 中已不在
 Datasource 中的 key

* remove leftDataSource and rightDatasource from this.state
pull/1596/head
RaoHai 9 years ago committed by afc163
parent a621522c56
commit 190aba24ee

@ -45,7 +45,6 @@ export default class Transfer extends React.Component {
constructor(props) {
super(props);
this.state = {
leftFilter: '',
rightFilter: '',
@ -53,9 +52,16 @@ export default class Transfer extends React.Component {
rightCheckedKeys: [],
};
}
splitDataSource() {
const { targetKeys, dataSource } = this.props;
componentWillReceiveProps(nextProps) {
const { leftCheckedKeys, rightCheckedKeys } = this.state;
const { leftDataSource, rightDataSource } = this.splitDataSource(nextProps);
this.setState({
leftCheckedKeys: leftCheckedKeys.filter(data => leftDataSource.filter(leftData => leftData.key === data).length),
rightCheckedKeys: rightCheckedKeys.filter(data => rightDataSource.filter(rightData => rightData.key === data).length),
});
}
splitDataSource(props) {
const { targetKeys, dataSource } = props;
let leftDataSource = [...dataSource];
let rightDataSource = [];
@ -99,7 +105,7 @@ export default class Transfer extends React.Component {
moveToRight = () => this.moveTo('right')
getGlobalCheckStatus(direction) {
const { leftDataSource, rightDataSource } = this.splitDataSource();
const { leftDataSource, rightDataSource } = this.splitDataSource(this.props);
const { leftFilter, rightFilter, leftCheckedKeys, rightCheckedKeys } = this.state;
const dataSource = direction === 'left' ? leftDataSource : rightDataSource;
@ -134,7 +140,7 @@ export default class Transfer extends React.Component {
}
handleSelectAll = (direction) => {
const { leftDataSource, rightDataSource } = this.splitDataSource();
const { leftDataSource, rightDataSource } = this.splitDataSource(this.props);
const { leftFilter, rightFilter } = this.state;
const dataSource = direction === 'left' ? leftDataSource : rightDataSource;
const filter = direction === 'left' ? leftFilter : rightFilter;
@ -201,7 +207,7 @@ export default class Transfer extends React.Component {
} = this.props;
const { leftFilter, rightFilter, leftCheckedKeys, rightCheckedKeys } = this.state;
const { leftDataSource, rightDataSource } = this.splitDataSource();
const { leftDataSource, rightDataSource } = this.splitDataSource(this.props);
const leftActive = rightCheckedKeys.length > 0;
const rightActive = leftCheckedKeys.length > 0;

Loading…
Cancel
Save