我有幾個動態生成的材質UI按鈕,當用戶點擊其中的任何一個時,我想知道哪些被點擊(假設獲得我在下面分配的name
屬性的值)。 這怎麼解決?基本上我想檢索被點擊的按鈕的一些屬性。 這裏是一些代碼檢索哪個按鈕被點擊反應/材質
{that.state.items.map(function (item) {
return (<div key = {item.id}>
<FlatButton label={item.regionName} name = {item.id} primary={true} onClick={that.handleRegionClick}></FlatButton>
</div>
)
})}
handleRegionClick(e)
{
console.log(e.target.name) // This prints undefined
// If I could get here the _item.id_ which I assigned to _name_ I would be fine.
}
PS。我也有這在構造函數
this.handleRegionClick = this.handleRegionClick.bind(this);
一個問題,你如何在任何循環內動態生成按鈕? –
@MayankShukla是的,在地圖 –