improve transfer demo code style

This commit is contained in:
afc163 2015-12-28 11:03:58 +08:00
parent 07656e7c50
commit 4564324621
3 changed files with 18 additions and 49 deletions

View File

@ -17,11 +17,9 @@ const App = React.createClass({
targetKeys: [],
};
},
componentDidMount() {
this.getMock();
},
getMock() {
let targetKeys = [];
let mockData = [];
@ -37,25 +35,17 @@ const App = React.createClass({
}
mockData.push(data);
}
this.setState({
mockData: mockData,
targetKeys: targetKeys,
});
this.setState({ mockData, targetKeys });
},
handleChange(targetKeys) {
this.setState({
targetKeys: targetKeys,
});
this.setState({ targetKeys });
},
renderFooter() {
return <Button type="ghost" size="small" style={{ float: 'right', margin: '5' }}
onClick={this.getMock}>刷新</Button>;
},
render() {
return <div>
return (
<Transfer
dataSource={this.state.mockData}
showSearch
@ -66,9 +56,9 @@ const App = React.createClass({
operations={['向右操作文案', '向左操作文案']}
targetKeys={this.state.targetKeys}
onChange={this.handleChange}
render={(item) => { return item.title + '-' + item.description; }}
render={item => item.title + '-' + item.description}
footer={this.renderFooter} />
</div>;
);
}
});

View File

@ -8,7 +8,6 @@
````jsx
import { Transfer, Button } from 'antd';
const container = document.getElementById('components-transfer-demo-basic');
const App = React.createClass({
getInitialState() {
@ -17,11 +16,9 @@ const App = React.createClass({
targetKeys: [],
};
},
componentDidMount() {
this.getMock();
},
getMock() {
let targetKeys = [];
let mockData = [];
@ -37,33 +34,25 @@ const App = React.createClass({
}
mockData.push(data);
}
this.setState({
mockData: mockData,
targetKeys: targetKeys,
});
this.setState({ mockData, targetKeys });
},
handleChange(targetKeys) {
this.setState({
targetKeys: targetKeys,
});
this.setState({ targetKeys });
},
renderFooter() {
return <Button type="primary" size="small" style={{ float: 'right', margin: '5' }}
onClick={this.getMock}>刷新</Button>;
},
render() {
return <div>
return (
<Transfer
dataSource={this.state.mockData}
targetKeys={this.state.targetKeys}
onChange={this.handleChange}
render={(item) => { return item.title; }} />
</div>;
render={item => item.title} />
);
}
});
ReactDOM.render(<App />, container);
ReactDOM.render(<App />, document.getElementById('components-transfer-demo-basic'));
````

View File

@ -8,7 +8,6 @@
````jsx
import { Transfer } from 'antd';
const container = document.getElementById('components-transfer-demo-search');
const App = React.createClass({
getInitialState() {
@ -17,11 +16,9 @@ const App = React.createClass({
targetKeys: [],
};
},
componentDidMount() {
this.getMock();
},
getMock() {
let targetKeys = [];
let mockData = [];
@ -37,29 +34,22 @@ const App = React.createClass({
}
mockData.push(data);
}
this.setState({
mockData: mockData,
targetKeys: targetKeys,
});
this.setState({ mockData, targetKeys });
},
handleChange(targetKeys) {
this.setState({
targetKeys: targetKeys,
});
this.setState({ targetKeys });
},
render() {
return <div>
return (
<Transfer
dataSource={this.state.mockData}
showSearch
targetKeys={this.state.targetKeys}
onChange={this.handleChange}
render={(item) => { return item.title;}} />
</div>;
render={item => item.title} />
);
}
});
ReactDOM.render(<App />, container);
ReactDOM.render(<App />, document.getElementById('components-transfer-demo-search'));
````