如何在 Meteor/React 中打开和关闭 Material-UI 对话框?

How do I open and close a Material-UI Dialog in Meteor/React?

我正在尝试在用户单击按钮时弹出一个带有表单的对话框。我几乎完全从 Dialog Material-UI 站点了解如何使用将用于打开对话框的按钮和在对话框中添加的 TextField 来执行此操作。这是使用 Meteor 和 React。当我在服务器上 运行 时出现错误。有人知道Missing class properties transform.是什么意思吗?

代码

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.

假设您使用的是 babel,如果更可取,则需要 class properties transform. It is included in the stage 2 preset。你在使用 webpack 打包吗?分享您的 webpack 配置,尤其是 loaders 中的 js/jsx 部分会很有帮助。

请参阅我的其他答案以使此代码正常工作,但如果您愿意,也可以完全避免使用 class 语法。

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>
    );
  }
})