【发布时间】:2015-01-03 09:23:36
【问题描述】:
我这里有这个组件。我想将调用处理程序传递给我创建的每个 listElement。如果我像下面那样使用bind(this),它可以正常工作。问题是我从控制台中的 React 收到此警告:bind(): You are binding a component method to the component. React does this for you automatically in a high-performance way, so you can safely remove this call.
var MyList = React.createClass({
render: function () {
var listElements = this.props.myListValues.map(function (val) {
return (
<ListElement onCallHandler={this.props.parentsCallHandler} val={val} />
);
}.bind(this));
return (
<ul>
{listElements}
</ul>
);
}
});
如果我不绑定它,我的孩子不知道调用处理程序。我可以做些什么不同的事情?
PS:
我知道解构分配,就像 http://facebook.github.io/react/docs/transferring-props.html#transferring-with-...-in-jsx 解释的那样,但我不想使用 Harmony。
【问题讨论】:
-
“调用处理程序”是指事件处理程序吗?事件应该冒泡到父级,并且可以在那里捕获。我错过了什么?
-
我没有看到那个错误:jsfiddle.net/s6dok0xv.
标签: javascript reactjs