【发布时间】:2021-05-03 18:33:23
【问题描述】:
我有一个下拉列表和一个对话框,当下拉列表中的项目(类dialogselected)被选中时显示
代码:
// function is triggered when an item in the drop-down list is selected
handleSelect = (eventKey: any, event: any) => {
this.setState({
selected_id: eventKey,
is_activated: event.target.classList.contains('dialogselected')
});
}
// display a drop-down list and a modal dialog
render() {
return (
<>
<Dropdown>
<Dropdown.Menu>
<Dropdown.Item
onSelect = {this.handleSelect}
>...</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
{this.state.is_activated ? <MyDialog /> : null}
</>
);
}
When an item with the class dialogselected is selected, the dialog is displayed.
如果我关闭对话框并再次选择相同的项目,则对话框将不会再次显示因为状态没有改变,即is_activated 是true 并保持不变。 p>
您能建议如何正确解决这种情况吗?
即该对话框需要重复调用,即我们需要以某种方式让 geast 知道状态已被拉出
【问题讨论】:
标签: reactjs state react-bootstrap setstate