4

我现在正在尝试material-ui。我是 react.js 和 material-ui 的新手,不知何故设法通过了一些东西,但不能使用 SelectField。每当我使用 SelectField 组件时,我都会得到一个

未捕获的类型错误:无法读取未定义错误的属性“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;

任何想法为什么它会输出错误?其他 material-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);

})();
4

0 回答 0