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

View File

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

View File

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