尝试使用material-ui SelectField组件时出错

时间:2015-06-24 04:17:04

标签: reactjs material-design react-jsx material-ui

我正在尝试使用材料-ui。我是react.js和material-ui的新手,并以某种方式设法通过一些东西,但不能使用SelectField。每当我使用SelectField组件时,我都会得到一个

  

未捕获的TypeError:无法读取undefinederror的属性'toUpperCase'。

我已按照以下方式编写:material-ui.com

这是我的selectField.jsx文件:

var React = require('react');
var mui = require('material-ui');
var SelectField = mui.SelectField;
var ThemeManager = new mui.Styles.ThemeManager();
var Colors = mui.Styles.Colors;
var StyleResizable = mui.Mixins.StyleResizable;

var menuItems = [
{ payload: '1', text: 'Never' },
{ payload: '2', text: 'Every Night' },
{ payload: '3', text: 'Weeknights' },
{ payload: '4', text: 'Weekends' },
{ payload: '5', text: 'Weekly' },
];

var Main = React.createClass({

  getInitialState: function() {
    return { selectValue: undefined};
  },

  childContextTypes: {
    muiTheme: React.PropTypes.object
  },

  getChildContext: function() {
    return {
      muiTheme: ThemeManager.getCurrentTheme()
    };
  },

  render: function() {
    return (
      <SelectField
      value={this.state.selectValue}
      onChange={this._handleSelectValueChange}
      floatingLabelText="Select Field"
      menuItems={menuItems} />
    );
  },

  _handleSelectValueChange: function(e) {
    this.setState({
      selectValue: e.target.value
    });
  }
});

module.exports = Main;

为什么输出错误的想法?其他材料-ui组件工作正常。

编辑:

这是我在app.jsx档案中的父组件:

(function () {
  var React = require('react');
  var injectTapEventPlugin = require('react-tap-event-plugin');
  var Main = require('./components/selectField.jsx'); 

  window.React = React;

  injectTapEventPlugin();

  React.render(<Main />, document.body);

})();

0 个答案:

没有答案