ant-design/components/queue-anim/demo/change.md

68 lines
1.5 KiB
Markdown
Raw Normal View History

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
import { QueueAnim, Button } from 'antd';
2015-10-23 22:37:42 +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>,
<li key="2"></li>
],
};
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() {
let items = this.state.items;
2015-10-21 17:53:38 +08:00
items.push(<li key={Date.now()}></li>);
this.setState({
show: true,
items,
2015-10-23 22:37:42 +08:00
});
2015-10-21 17:53:38 +08:00
},
onRemove() {
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,
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>
<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">
2015-10-23 22:37:42 +08:00
<div className="demo-listBox" key="b">
2015-10-21 17:53:38 +08:00
<div className="demo-list">
<div className="title"></div>
2015-10-23 22:37:42 +08:00
<QueueAnim component="ul" type={['right', 'left']}>
{this.state.show ? this.state.items : null}
2015-10-21 17:53:38 +08:00
</QueueAnim>
</div>
</div>
</div>
</div>
);
}
});
ReactDOM.render(<Test />, mountNode);
2015-10-21 17:53:38 +08:00
````