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.

71 lines
1.5 KiB

---
order: 2
title: 高级用法
---
9 years ago
穿梭框高级用法,可配置操作文案,可定制宽高,可对底部进行自定义渲染。
9 years ago
````jsx
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,
title: `内容${i + 1}`,
description: `内容${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}
>
刷新
</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={['向右操作文案', '向左操作文案']}
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
````