2016-03-02 91 views
-1

Menu組件的大多數屬性不起作用,例如, onChange屬性不起作用當我點擊MenuItem,但onClick功能它確實工作,我真的不知道如何解決這個問題。material-ui組件屬性不起作用

import React from 'react'; 
    import ReactDOM from 'react-dom'; 
    import Menu from 'material-ui/src/menus/menu'; 
    import MenuItem from 'material-ui/src/menus/menu-item'; 


    class Contacts extends React.Component { 
     constructor(props) { 
      super(props); 
     } 

     handleClick =(e)=> { 
      console.log(e) 
     }; 
     handleChange =(e)=> { 
      console.log(e.target) 
     }; 
     render() { 
      const style = { 
       marginRight: 33, 
       marginBottom: 33, 
       float: 'left', 
       position: 'relative', 
       zIndex: 10, 
      }; 
      return (
       <Menu style={style} onClick={this.handleClick} onChange={this.handleChange}> 
        <MenuItem primaryText="Maps" /> 
        <MenuItem primaryText="Books" /> 
        <MenuItem primaryText="Flights" /> 
        <MenuItem primaryText="Apps" /> 
       </Menu> 
      ); 
     } 
    } 
    console.log(<Contacts/>); 
    ReactDOM.render(<Contacts/>,document.getElementById('example')); 
+0

如果你只是在handleChange登錄E(而不是e.target),做這個節目的東西嗎? –

+0

我知道它的菜單項不具備價值 – gowa

回答

0

這是一樣的this問題

下面將解決這一問題,

constructor(props) { 
    super(props); 
    this.handleClick = this.handleClick.bind(this); 
    this.handleChange = this.handleChange.bind(this); 
    } 

    handleClick(e) function { 
    console.log(e) 
    } 
    handleChange (e) function { 
    console.log(e.target) 
    }