[英]React js calling static function into another static function on onclick event in html button
請找出以下代碼:
var ResultComponent = React.createClass({
getInitialState: function () {
// … Some code …….
},
handleClick: function(event) {
// … Some code …….
// Include html (displaying data)
this.constructor.searchResultMethod(para,para1,para2)
},
statics: {
deleteMethod: function(para = ''){
console.log(para);
});
searchResultMethod: function(){
var html = ‘’
loop{
var html += '<button id="button" onClick="'+ResultComponent.deleteMethod(1)+'"> delete </button>';
}
}
render: function() {
return (
<div>
<button className={this.state.classes} id={this.state.execute} onClick={this.handleClick} >Execute</button>
<button className={this.state.classes} id={this.state.save} onClick={this.handleClick}>Save</button>
</div>
);
}
});
我在這里重新執行並保存。 在handleClick中定義動作,在此將html與動作一起添加到delete中,然后調用deleteMethod函數。
在這里,我將靜態函數deleteMethod調用到另一個稱為searchResultMethod的靜態函數中,但是onclick事件在加載頁面而不是單擊按鈕時自動觸發。 我是Reactjs的新手。 需要解決方案。
嘗試ResultComponent.deleteMethod(1),因為需要在類上訪問靜態方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.