[英]Cannot read property [function] of undefined
我在渲染函數的返回部分中包含以下內容:
<table>
<tbody>
{nums.map(function(num, index){
return <tr key={ index }>{num} <input type="submit" value="unmatch" onClick={this.unMatchButtonClicked} />
</tr>;
})}
</tbody>
</table>
但是,當我加載頁面時,我收到一條錯誤消息: Cannot read property 'unMatchButtonClicked' of undefined
即使它是在render:function()
之前的render:function()
unMatchButtonClicked: function(){
console.log('called');
},
那么,什么是范圍this
和它為什么不確定?
Array.map(function () {/*...*/}, this)
var unMatchButtonClicked = this.unMatchButtonClicked
和onClick={unMatchButtonClicked}
除此之外,你應該考慮使用箭頭功能,點擊后處理程序或綁定this
給你的函數。
http://egorsmirnov.me/2015/08/16/react-and-es6-part3.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.