diff --git a/components/transfer/index.jsx b/components/transfer/index.jsx index 6ab90fae61..c9651b8d80 100644 --- a/components/transfer/index.jsx +++ b/components/transfer/index.jsx @@ -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;