我有一個項目列表,並在點擊刪除按鈕時,該項目將被刪除。我知道要做到這一點的步驟,但我被困在如何將密鑰傳遞給dlt_item作用域。從函數到函數的傳遞索引
http://jsfiddle.net/3Ley7uac/1/
var App = React.createClass({
getInitialState(){
return {
items:[1,2,3]
}
},
dlt_item(key){
//how to get index/id here?
},
renderItem(){
return this.state.items.map((item,i)=> <li key={i}>{item}
<button>Edit</button>
<button onClick={this.dlt_item}>Delete</button>
</li>
)
},
render(){
return(
<ul>
{this.renderItem()}
</ul>
)
}
})
除了使用拼接,U可以這樣做過濾器? –
如何操作鑰匙是您的選擇。拼接是我找到的最簡單的方法。您也可以過濾掉數據 –