简体   繁体   English

当第一个 select 选项更改时清除 select 框中的内容 - reactJS

[英]Clear content in select box when first select option changed - reactJS

I am new to ReactJS .我是ReactJS的新手。 I have used AntJS select in my ReactJS project.我在我的ReactJS项目中使用AntJS select。 I have two select in HTML .我在HTML select When the first select is selected, its relative dropdown will be loaded in the second select .选择first select时,其相关下拉列表将加载到second select中。

UI View:用户界面视图: 在此处输入图像描述

When the user chooses the option in the first select , the second select will load its contents.当用户选择first select中的选项时, second select将加载其内容。

It was working great.它工作得很好。 Now my issue was " When I choose an option in second select , it is there in the second select box . But When I changed the option in the first select , the already chosen option in the second select is still there, but the drop-down content in the second select has changed.现在我的问题是“当我在second select中选择一个选项时,它就在second select box 。但是当我在第first select中更改选项时, second select中已经选择的选项仍然存在,但下降 - second select中的内容已更改。

My Issue in UI View:我在 UI 视图中的问题: 在此处输入图像描述 How to clear the selected content in the second select box when the first select option has changed". I have tried so far. I don't how to make it possible. Help me with some solutions.当第first select选项发生变化时,如何清除second select框中的所选内容”。到目前为止我已经尝试过了。我不知道如何让它成为可能。帮我解决一些问题。

Code:代码:

WAAccountNameChange(value){  
        this.setState({selectedValue:"", waWebsiteList: this.state.waAccountWebsiteList[value] }) 
    }

First Select:第一个 Select:

<Select  " onChange= {(value) => { this.WAAccountNameChange(value)}} >
    {this.state.waAccountList.map((item, index) => <Select.Option value={item} key={index}>{item}</Select.Option>)}
</Select>

Second Select:第二个Select:

<Select  defaultValue={this.state.selectedValue}  onChange= {(value) => { this.setState({ selectedValue: value })} } >
    {this.state.waWebsiteList.map((item, index) => <Select.Option value={item} key={index}>{item}</Select.Option>)}
</Select>

On the change of first select menu clear the value of second select box.在更改第一个 select 菜单时,清除第二个 select 框的值。 If you retrieve data from API than clear state on API success.如果您从 API 检索数据比清除 state API 成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM