[英]How can i pass data in reactstrap modal when specific button id is click?
如果單擊特定的按鈕區域ID,如何從模態中傳遞數據? 例如我有下面列出的對象,並有2個按鈕。 如何將我的區域傳遞到各個按鈕?
這是我定義狀態的方式。
constructor(props) {
super(props);
this.state = {
data: Data,
modal: false
};
this.toggle = this.toggle.bind(this);
}
toggle(item) {
this.setState({
modal: !this.state.modal
});
}
這是我的按鈕。 兩次
<Button onClick={this.toggle} color="info" size="sm" block>Zone 1</Button>
<Button onClick={this.toggle} color="info" size="sm" block>Zone 2</Button>
這是數據。
data:[{
"Assignment": "52041",
"Zone": "1"
},
{
"Assignment": "52042",
"Zone": "2"
}]
您可以像下面這樣通過onClick傳遞數據。
class Test {
constructor(props) {
super(props);
this.state = {
data: Data,
modal: false
};
this.toggle = this.toggle.bind(this);
}
toggle(item) {
this.setState({
modal: !this.state.modal
});
}
render() {
const data=[{
"Assignment": "52041",
"Zone": "1"
},
{
"Assignment": "52042",
"Zone": "2"
}];
return (
<div>
<Button onClick={()=>this.toggle(data)} color="info" size="sm" block>Zone 1</Button>
<Button onClick={()=>this.toggle(data)} color="info" size="sm" block>Zone 2</Button>
</div>
)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.