我试图在用户单击按钮时弹出一个带有表单的对话框。我几乎完全取自 Dialog Material-UI有关如何使用用于打开对话框的按钮和在对话框中添加的文本字段来执行此操作的站点。这是使用 Meteor 和 React。当我在服务器上运行时出现错误。有人知道缺少类属性转换。
是什么意思吗?
代码
import React from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import ContentAdd from 'material-ui/svg-icons/content/add';
import TextField from 'material-ui/TextField';
const style = {
marginRight: "20px",
position: "absolute",
left: "80%",
down: "80%",
};
export default class Events extends React.Component {
state = {
open: false,
};
handleOpen = () => {
this.setState({open: true});
};
handleClose = () => {
this.setState({open: false});
};
render() {
const actions = [
<FlatButton
label="Cancel"
primary={true}
onTouchTap={this.handleClose}
/>,
<FlatButton
label="Submit"
primary={true}
keyboardFocused={true}
onTouchTap={this.handleClose}
/>,
];
return (
<div>
<h1>Events</h1>
<FloatingActionButton style={style}>
<ContentAdd />
</FloatingActionButton>
<Dialog
title="Add Event"
actions={actions}
model={false}
open={this.state.open}
onRequestClose={this.handClose}
>
<TextField
hintText="Hint Text"
floatingLabelText="Floating Label Text"
/>
</Dialog>
</div>
);
}
}
错误
Errors prevented startup:
While processing files with ecmascript (for target web.browser):
client/events/Events.jsx:20:2: /client/events/Events.jsx: Missing class properties transform.
Your application has errors. Waiting for file change.
最佳答案
请参阅我的其他答案以了解如何使此代码正常工作,但如果您愿意,也可以完全避免使用类语法。
import React from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import ContentAdd from 'material-ui/svg-icons/content/add';
import TextField from 'material-ui/TextField';
const style = {
marginRight: "20px",
position: "absolute",
left: "80%",
down: "80%",
};
export default const Events = React.createClass({
getInitialState: function () {
return {
open: false
}
},
handleOpen: () => {
this.setState({open: true});
},
handleClose: () => {
this.setState({open: false});
},
render: function() {
const actions = [
<FlatButton
label="Cancel"
primary={true}
onTouchTap={this.handleClose}
/>,
<FlatButton
label="Submit"
primary={true}
keyboardFocused={true}
onTouchTap={this.handleClose}
/>,
];
return (
<div>
<h1>Events</h1>
<FloatingActionButton style={style}>
<ContentAdd />
</FloatingActionButton>
<Dialog
title="Add Event"
actions={actions}
model={false}
open={this.state.open}
onRequestClose={this.handClose}
>
<TextField
hintText="Hint Text"
floatingLabelText="Floating Label Text"
/>
</Dialog>
</div>
);
}
})
关于javascript - 如何在 Meteor/React 中打开和关闭 Material-UI 对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39554452/