From 9c83538621b3cae052abd4e8f675e8572f832269 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Fri, 30 Sep 2016 17:45:58 +0800 Subject: [PATCH] fix: should work with getFieldDecorator (#3251) --- components/transfer/index.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/transfer/index.tsx b/components/transfer/index.tsx index 605bfe9c8a..0627170751 100644 --- a/components/transfer/index.tsx +++ b/components/transfer/index.tsx @@ -1,9 +1,9 @@ import React from 'react'; import { PropTypes } from 'react'; +import classNames from 'classnames'; import List from './list'; import Operation from './operation'; import Search from './search'; -import classNames from 'classnames'; function noop() { } @@ -46,7 +46,6 @@ export default class Transfer extends React.Component { prefixCls: 'ant-transfer', dataSource: [], render: noop, - targetKeys: [], onChange: noop, onSelectChange: noop, titles: ['源列表', '目的列表'], @@ -95,15 +94,16 @@ export default class Transfer extends React.Component { // clear cached splited dataSource this.splitedDataSource = null; - const { dataSource, targetKeys } = nextProps; + const { dataSource, targetKeys = [] } = nextProps; + function existInDateSourcekey(key) { + return dataSource.filter(item => item.key === key).length; + } // clear key nolonger existed // clear checkedKeys according to targetKeys this.setState({ - leftCheckedKeys: leftCheckedKeys - .filter(data => dataSource.filter(item => item.key === data).length) + leftCheckedKeys: leftCheckedKeys.filter(existInDateSourcekey) .filter(data => targetKeys.filter(key => key === data).length === 0), - rightCheckedKeys: rightCheckedKeys - .filter(data => dataSource.filter(item => item.key === data).length) + rightCheckedKeys: rightCheckedKeys.filter(existInDateSourcekey) .filter(data => targetKeys.filter(key => key === data).length > 0), }); } @@ -113,7 +113,7 @@ export default class Transfer extends React.Component { return this.splitedDataSource; } - const { dataSource, targetKeys } = props; + const { dataSource, targetKeys = [] } = props; if (props.rowKey) { dataSource.forEach(record => { record.key = props.rowKey(record); @@ -138,7 +138,7 @@ export default class Transfer extends React.Component { } moveTo = (direction) => { - const { targetKeys, onChange } = this.props; + const { targetKeys = [], onChange } = this.props; const { leftCheckedKeys, rightCheckedKeys } = this.state; const moveKeys = direction === 'right' ? leftCheckedKeys : rightCheckedKeys; // move items to target box