You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.7 KiB

---
order: 2
title:
zh-CN: 高级用法
en-US: Advanced
---
9 years ago
## zh-CN
穿梭框高级用法,可配置操作文案,可定制宽高,可对底部进行自定义渲染。
9 years ago
## en-US
Advanced Usage of Transfer.
You can customize the labels of the transfer buttons, the width and height of the columns, and what should be displayed in the footer.
````__react
9 years ago
import { Transfer, Button } from 'antd';
9 years ago
9 years ago
const App = React.createClass({
getInitialState() {
return {
9 years ago
mockData: [],
targetKeys: [],
9 years ago
};
},
componentDidMount() {
this.getMock();
},
getMock() {
const targetKeys = [];
const mockData = [];
9 years ago
for (let i = 0; i < 20; i++) {
9 years ago
const data = {
key: i.toString(),
title: `content${i + 1}`,
description: `description of content${i + 1}`,
chosen: Math.random() * 2 > 1,
9 years ago
};
if (data.chosen) {
targetKeys.push(data.key);
}
mockData.push(data);
9 years ago
}
this.setState({ mockData, targetKeys });
9 years ago
},
9 years ago
handleChange(targetKeys) {
this.setState({ targetKeys });
9 years ago
},
renderFooter() {
return (
<Button type="ghost" size="small" style={{ float: 'right', margin: 5 }}
onClick={this.getMock}
>
reload
</Button>
);
9 years ago
},
9 years ago
render() {
return (
9 years ago
<Transfer
dataSource={this.state.mockData}
showSearch
9 years ago
listStyle={{
9 years ago
width: 250,
9 years ago
height: 300,
}}
operations={['to right', 'to left']}
9 years ago
targetKeys={this.state.targetKeys}
onChange={this.handleChange}
render={item => `${item.title}-${item.description}`}
footer={this.renderFooter}
/>
);
},
9 years ago
});
ReactDOM.render(<App />, mountNode);
9 years ago
````