mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 11:40:04 +08:00
Merge pull request #1905 from RaoHai/transferRowkey
add rowKey props to Transfer
This commit is contained in:
commit
3bdacbc9bc
@ -41,6 +41,7 @@ export default class Transfer extends React.Component {
|
||||
notFoundContent: PropTypes.node,
|
||||
body: PropTypes.func,
|
||||
footer: PropTypes.func,
|
||||
rowKey: PropTypes.func,
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
@ -61,8 +62,15 @@ export default class Transfer extends React.Component {
|
||||
});
|
||||
}
|
||||
splitDataSource(props) {
|
||||
const { targetKeys, dataSource } = props;
|
||||
const { targetKeys } = props;
|
||||
let { dataSource } = props;
|
||||
|
||||
if (props.rowKey) {
|
||||
dataSource = dataSource.map(record => {
|
||||
record.key = props.rowKey(record);
|
||||
return record;
|
||||
});
|
||||
}
|
||||
let leftDataSource = [...dataSource];
|
||||
let rightDataSource = [];
|
||||
|
||||
|
@ -29,3 +29,14 @@ english: Transfer
|
||||
| searchPlaceholder | 搜索框的默认值 | String | '请输入搜索内容' |
|
||||
| notFoundContent | 当列表为空时显示的内容 | React.node | '列表为空' |
|
||||
| footer | 底部渲染函数 | Function(props) | |
|
||||
|
||||
|
||||
## 注意
|
||||
|
||||
按照 React 的[规范](http://facebook.github.io/react/docs/multiple-components.html#dynamic-children),所有的组件数组必须绑定 key。在 Transfer 中,`dataSource`里的数据值需要指定 `key` 值。对于 `dataSource` 默认将每列数据的 `key` 属性作为唯一的标识。
|
||||
|
||||
如果你的数据没有这个属性,务必使用 `rowKey` 来指定数据列的主键。
|
||||
```jsx
|
||||
// 比如你的数据主键是 uid
|
||||
return <Transfer rowKey={record => record.uid} />;
|
||||
```
|
Loading…
Reference in New Issue
Block a user