2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 5
|
|
|
|
title: 添加与删除
|
|
|
|
---
|
2015-10-21 17:53:38 +08:00
|
|
|
|
2015-10-23 22:37:42 +08:00
|
|
|
场景里有增加或删除条目时也会触发动画。
|
2015-10-21 17:53:38 +08:00
|
|
|
|
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { QueueAnim, Button } from 'antd';
|
2015-10-23 22:37:42 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const Test = React.createClass({
|
2015-10-21 17:53:38 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
show: true,
|
2015-10-23 22:37:42 +08:00
|
|
|
items: [
|
|
|
|
<li key="0"></li>,
|
|
|
|
<li key="1"></li>,
|
2016-05-11 09:32:33 +08:00
|
|
|
<li key="2"></li>,
|
2015-10-23 22:37:42 +08:00
|
|
|
],
|
|
|
|
};
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
onClick() {
|
|
|
|
this.setState({
|
|
|
|
show: !this.state.show,
|
2015-10-23 22:37:42 +08:00
|
|
|
});
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
onAdd() {
|
2015-10-28 20:55:49 +08:00
|
|
|
let items = this.state.items;
|
2015-10-21 17:53:38 +08:00
|
|
|
items.push(<li key={Date.now()}></li>);
|
|
|
|
this.setState({
|
|
|
|
show: true,
|
2016-02-17 15:57:33 +08:00
|
|
|
items,
|
2015-10-23 22:37:42 +08:00
|
|
|
});
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
onRemove() {
|
2015-10-28 20:55:49 +08:00
|
|
|
let items = this.state.items;
|
2015-10-23 22:37:42 +08:00
|
|
|
items.splice(items.length - 1, 1);
|
2015-10-21 17:53:38 +08:00
|
|
|
this.setState({
|
|
|
|
show: true,
|
2016-02-17 15:57:33 +08:00
|
|
|
items,
|
2015-10-23 22:37:42 +08:00
|
|
|
});
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
2015-10-23 22:37:42 +08:00
|
|
|
<p className="buttons">
|
2015-10-21 17:53:38 +08:00
|
|
|
<Button type="primary" onClick={this.onClick}>切换</Button>
|
2016-01-27 16:44:50 +08:00
|
|
|
<Button onClick={this.onAdd} style={{ marginLeft: 10 }}>添加</Button>
|
|
|
|
<Button onClick={this.onRemove} style={{ marginLeft: 10 }}>删除</Button>
|
2015-10-23 22:37:42 +08:00
|
|
|
</p>
|
2015-10-21 17:53:38 +08:00
|
|
|
<div className="demo-content">
|
2016-04-29 12:13:27 +08:00
|
|
|
<div className="demo-listBox" key="b">
|
|
|
|
<div className="demo-list">
|
|
|
|
<div className="title"></div>
|
|
|
|
<QueueAnim component="ul" type={['right', 'left']}>
|
|
|
|
{this.state.show ? this.state.items : null}
|
|
|
|
</QueueAnim>
|
2015-10-21 17:53:38 +08:00
|
|
|
</div>
|
2016-04-29 12:13:27 +08:00
|
|
|
</div>
|
2015-10-21 17:53:38 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2016-05-11 09:32:33 +08:00
|
|
|
},
|
2015-10-21 17:53:38 +08:00
|
|
|
});
|
|
|
|
|
2015-12-29 12:08:58 +08:00
|
|
|
ReactDOM.render(<Test />, mountNode);
|
2015-10-21 17:53:38 +08:00
|
|
|
````
|