美文网首页
react function 参数处理

react function 参数处理

作者: fourzyz | 来源:发表于2017-03-05 13:51 被阅读0次

render: function() { return <p onClick={this.handleClick.bind(this, 'extra param')}>;}

handleClick: function(param, event) { // handle click}

由上面可以看出,Event一般都是作为最后一个参数传递到handleClick中,这里的event是SyntheticEvent对象,它的主要属性如下:

在React中,也会经常遇到需要为某个群组绑定事件的情况,可以参考如下代码:

var GroceryList = React.createClass({ handleClick: function(i) { console.log('You clicked: ' + this.props.items[i]); }, render: function() { return ( <div> {this.props.items.map(function(item, i) { return ( <div onClick={this.handleClick.bind(this, i)} key={i}>{item}</div> ); }, this)} </div> ); }});React.render( <GroceryList items={['Apple', 'Banana', 'Cranberry']} />, mountNode);

相关文章

网友评论

      本文标题:react function 参数处理

      本文链接:https://www.haomeiwen.com/subject/ozduuttx.html