当我单击左侧的元素AppBar图标时,应该执行_handleClick()方法.我无法获得控制台消息.我正在使用material-ui框架,并且为通过触摸选择选择左图标时的回调函数提供了属性onLeftIconButtonTouchTap.
import React, { Component } from 'react' import { AppBar, IconButton } from 'material-ui' import MoreVertIcon from 'material-ui/lib/svg-icons/navigation/more-vert'; let injectTapEventPlugin = require("react-tap-event-plugin"); //Needed for onTouchTap //Can go away when react 1.0 release //Check this repo: //https://github.com/zilverline/react-tap-event-plugin injectTapEventPlugin(); class Header extends Component { constructor(props) { super(props); this._handleClick = this._handleClick.bind(this); } _handleClick(e) { e.preventDefault(); // Show/Hide the LeftMenu window.console.log("Click!"); } render() { return (} onLeftIconButtonTouchTap={ this._handleClick } isInitiallyOpen={ true } /> ) } } export default Header
但它适用于另一个组件:
class Prueba extends Component { constructor(props) { super(props); this._handleClick = this._handleClick.bind(this); } _handleClick(e) { e.preventDefault(); window.console.log("Click!"); } render (){ return (Prueba Prueba Prueba
) } } export default Prueba;
user2670996.. 8
如果为AppBar组件指定图标,则onLeftIconButtonTouchTap事件不起作用.要么您没有指定图标:
或者您在IconButton组件上应用事件:
} isInitiallyOpen={ true } />
编辑:请注意,根据这个GitHub问题,应该解决问题.你仍然不能AA _handleClick
对两者的iconElementLeft
和onLeftIconButtonTouchTap
,一方或另一方.
如果为AppBar组件指定图标,则onLeftIconButtonTouchTap事件不起作用.要么您没有指定图标:
或者您在IconButton组件上应用事件:
} isInitiallyOpen={ true } />
编辑:请注意,根据这个GitHub问题,应该解决问题.你仍然不能AA _handleClick
对两者的iconElementLeft
和onLeftIconButtonTouchTap
,一方或另一方.