[英]React binding events within a function
我想將參數傳遞給onClick函數,但它會在返回時繼續觸發。 我相信我需要綁定點擊處理程序,但是我不確定如何做到這一點。
function (phone_calls, right_side, before_children) { function test (blah){ console.log(blah) } return boxy( "Phone Calls", _.map(phone_calls, function(a) { return d("div.splitter-wrap", {onClick: test("testarg")}, [ d("table.splitter", { className: name}, d("tr", [d('td',a.date),d('td',a.number)] )) ]); }),
您可以使用箭頭功能,例如:
{ onClick: ()=> { test("testarg") } }
否則,您可以使用bind,例如:
{ onClick: test.bind(this, "testarg") }
但這更加冗長,並且具有設置this
的(可能)有害的副作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.