我正在处理一个组件存根,其中有一个瓷砖网格,每个都需要点击处理程序,以及一个具有不同点击处理程序的特定“新”瓷砖。我试图使点击处理程序正常工作,但事件似乎从未触发。
有什么想法吗?
有什么想法吗?
var grid = React.createClass({
onCreateNew: function () {
console.log("onCreateNew");
},
render: function () {
var tiles = [];
if (this.props.items) {
tiles = this.props.items.map(function (item, index) {
//create a tile for each item
});
}
//always append "new" tile for the last one
tiles.push(React.DOM.div({
onClick: this.onCreateNew, className: "tile new_tile"
},
React.DOM.div({ className: "plus", onClick: this.onCreateNew }, "+")
));
return React.DOM.div({ id: "flowsheetPane" }, tiles);
}
});
map
调用中绑定了其他的onClick
?如果你打算引用组件,一定要将this
作为上下文传递,否则this
将等于window
:this.props.items.map(function() ..., this);
- Ross Allen