用下面的代碼我得到第9行錯誤
語法錯誤:意外的標記(9:10)有人可以告訴我這個代碼的問題以及如何解決它。編譯問題與反應jsx組件
import React from 'react';
import {SelectField, MenuItem, getMuiTheme, MuiThemeProvider,Stepper,Step,StepLabel,StepButton,StepContent} from 'material-ui'
import injectTapEventPlugin from 'react-tap-event-plugin';
import RaisedButton from 'material-ui/RaisedButton';
import FlatButton from 'material-ui/FlatButton';
class StepperComponent extends React.Component{
state = {
stepIndex: 0,
}
handleNext =() => {
const {stepIndex} = this.state;
if (stepIndex < 2) {
this.setState({stepIndex: stepIndex + 1});
}
};
handlePrev =() => {
const {stepIndex} = this.state;
if (stepIndex > 0) {
this.setState({stepIndex: stepIndex - 1});
}
};
renderStepActions(step) {
return (
<div style={{margin: '12px 0'}}>
<RaisedButton
label="Next"
disableTouchRipple={true}
disableFocusRipple={true}
primary={true}
onTouchTap={this.handleNext}
style={{marginRight: 12}}
/>
{step > 0 && (
<FlatButton
label="Back"
disableTouchRipple={true}
disableFocusRipple={true}
onTouchTap={this.handlePrev}
/>
)}
</div>
);
}
render() {
const {stepIndex} = this.state;
return (
<div style={{maxWidth: 380, maxHeight: 400, margin: 'auto'}}>
<MuiThemeProvider muiTheme={getMuiTheme}>
<Stepper
activeStep={stepIndex}
linear={false}
orientation="vertical"
>
<Step>
<StepButton onClick={() => this.setState({stepIndex: 0})}>
GROUP NAME
</StepButton>
<StepContent>
<p>
Add group name and description selection component here
</p>
{this.renderStepActions(0)}
</StepContent>
</Step>
<Step>
<StepButton onClick={() => this.setState({stepIndex: 1})}>
STUDENT
</StepButton>
<StepContent>
<p> Add student component here </p>
{this.renderStepActions(1)}
</StepContent>
</Step>
<Step>
<StepButton onClick={() => this.setState({stepIndex: 2})}>
VERIFY
</StepButton>
<StepContent>
<p>
Add verify group component here
</p>
{this.renderStepActions(2)}
</StepContent>
</Step>
</Stepper>
</MuiThemeProvider>
</div>
);
}
}
export default StepperComponent;
如果我用下面的替代語法那麼就沒有給我任何的編譯錯誤,但不知何故按鈕單擊事件不工作。
constructor(props) {
super(props);
this.state = {
stepIndex: 0,
};
}
handleNext() {
const {stepIndex} = this.state;
if (stepIndex < 2) {
this.setState({stepIndex: stepIndex + 1});
}
};
handlePrev() {
const {stepIndex} = this.state;
if (stepIndex > 0) {
this.setState({stepIndex: stepIndex - 1});
}
};
我做了修改的建議,但一些如何現在還沒有工作,如果可能的話,請提供工作樣品的jsfiddle。這是一個代碼從材料Ui網站http://www.material-ui.com/#/components/stepper請檢查垂直非線性步進。例。 – Sachin
你能詳細說明什麼不起作用(錯誤/警告......)嗎? – Pineda
它不會觸發任何按鈕上的點擊事件。 – Sachin