我在React JS中渲染表格數據,並且無法讓我的表格行隱藏在點擊「刪除」按鈕上。我現在的處理和渲染功能如下:如何在React JS中單擊子「刪除」按鈕時刪除父錶行?
...
changeHandler: function(e) {
...
},
deleteHandler: function(e) {
e.currentTarget.closest("tr").style.visibility = "hidden";
},
render: function() {
return (
<div>
<div class="container">
<select onChange={ this.changeHandler.bind(this) }>
<option></option>
...
</select>
<table>
<thead>
<tr>
...
</tr>
</thead>
<tbody>
{data.map(function(row, j) {
return <tr key={j}>
<td>{row.text}</td>
<td><a href="" onClick={this.deleteHandler.bind(this, j)}>delete</a></td>
</tr>
}
)}
</tbody>
</table>
</div>
</div>
);
}
...
當我點擊刪除錨點,我得到這個錯誤在控制檯:
Uncaught TypeError: Cannot read property 'bind' of undefined
我不明白爲什麼我的刪除處理ISN當我使用changeHandler的時候,我不會被識別和綁定。請告訴我如何讓這個事件觸發處理程序,以及如何定位父tr以隱藏它?
我們可以得到更多的代碼或一小塊的=> codepen?有一支es6筆你可以分叉...嘗試綁定(null,j)?在黑暗的W/O例子中直接射擊。 – Mintberry
這有一切,但刪除處理程序實施。 – kurofune
嘗試[此鏈接](https://jsfiddle.net/ssbdnbw8/12/) – kurofune