ant-design/components/steps/demo/step-next.md

59 lines
1.2 KiB
Markdown
Raw Normal View History

2015-06-25 20:01:20 +08:00
# 切换到下一步
2015-06-25 16:01:04 +08:00
- order: 3
2015-09-01 17:43:08 +08:00
随机生成 3~6 个步骤,初始随机进行到其中一个步骤。
2015-06-25 20:01:20 +08:00
2015-06-25 18:12:42 +08:00
---
2015-07-08 16:36:08 +08:00
````css
2015-09-16 16:28:57 +08:00
#components-steps-demo-step-next > div > div {
2015-07-08 16:36:08 +08:00
margin-bottom: 30px;
2015-06-25 18:12:42 +08:00
}
2015-07-08 16:36:08 +08:00
````
2015-06-25 16:01:04 +08:00
````jsx
2015-07-08 16:36:08 +08:00
var Steps = antd.Steps;
var Step = Steps.Step;
2015-06-25 18:12:42 +08:00
var container = document.getElementById('components-steps-demo-step-next');
2015-09-16 16:28:57 +08:00
var array = Array.apply(null, Array(Math.floor(Math.random() * 3) + 3));
var steps = array.map(function(item, i) {
return {
title: '步骤' + (i + 1)
};
});
2015-06-25 18:12:42 +08:00
2015-09-16 16:28:57 +08:00
var App = React.createClass({
2015-06-25 18:12:42 +08:00
getInitialState() {
return {
currentStep: Math.floor(Math.random() * steps.length)
}
},
2015-09-16 16:28:57 +08:00
next() {
2015-06-25 18:12:42 +08:00
var s = this.state.currentStep + 1;
if (s === steps.length) {
s = 0;
}
this.setState({
currentStep: s
});
},
render() {
var cs = this.state.currentStep;
2015-09-16 16:28:57 +08:00
return (
<div>
<div>当前正在执行第 {cs + 1} 步</div>
<Steps current={cs}>
{steps.map((s, i) => <Step key={i} title={s.title} description={s.description} />)}
</Steps>
<div>
<button className='ant-btn' onClick={this.next}>下一步</button>
</div>
</div>
);
2015-06-25 18:12:42 +08:00
}
});
2015-09-16 16:28:57 +08:00
React.render(<App />, container);
2015-06-25 20:01:20 +08:00
````