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

标签 javascript reactjs meteor material-design material-ui

我试图在用户单击按钮时弹出一个带有表单的对话框。我几乎完全取自 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/

相关文章:

javascript - 迭代 html 模板中的数组字段

meteor - 如何显式退订收藏?

javascript - jQuery 如果元素有类就做某事

javascript - SAPUI5 - 更新 View

node.js - Node 错误_xdl(...).ProjectUtils.readConfigJsonAsync不是函数

javascript - 如何使用 firebase 更新集合中的许多记录?

javascript - 在jquery中检测两个div是否互相传递

javascript - 弹跳球在碰撞时错过了一些平台

javascript - 如何使用 Expo AV 重播音轨

node.js - Meteor 始终监听端口 3000