一个函数内的组件功能我有一个布局这样的组件:调用从Reactjs
var Entry = React.createClass({
// executes code on a button press.
onButtonClick: function (event) {
// (do stuff)
},
// generates the entry list with a button and some info.
render: function() {
var entryList= this.props.data.map(function(entry) {
// (convert timestamp into relative time, add some tags etc)
return (
<p> entry.information </p>
<a onClick={onButtonClick} className="btn right" id={entry.link}>
go
</a>
);
});
// returns the html of the component
return (
<div className="entryList">
{entryList}
</div>
);
}
});
我希望能够从entryList变量中在渲染运行函数onButtonClick功能,但我似乎无法弄清楚如何做到这一点。当运行它时,控制台说onButtonClick没有被定义。
Uncaught ReferenceError: onButtonClick is not defined
如何“逃避”功能?我认为这是this.props.data.map(function(items) {});
问题是什么复杂的,因为我可以,如果我移动的按钮这样
// returns the html of the component
return (
<div className="entryList">
<a onClick={this.onButtonClick} className="btn right">go</a>
{entryList}
</div>
);
}
});
感谢您的帮助就好了上网了!
,则应该设置'this'为'.map' - 'this.props.data.map(函数(进入){},这个)' –