React-Select isMulti检索选择的选项

问题描述 投票:0回答:1

我目前正在从事springboot / reactjs项目。我正在使用react select库在我的一种表单中设置多选输入,但是我无法获取所选值,这里有一些代码可以使它更加清晰。these are my options generated dynamically from the database each option has the webService Id as a value

this is my select input, I need to get the selected values "Ids" and then call the method that retrieves the webservices from the database and then assign the list of webServices to my newApplicationData.webservices

this is the get web service function

reactjs react-select
1个回答
0
投票

更新:我好心地找到了解决我问题的方法:在我使用过的onChange道具上

     onChange={(selectedOptions) => {
                const state = this.state;
                state.selectedWebServices = [];
                selectedOptions.forEach((option) => {
                  this.getWS(option.value);
                  state.selectedWebServices.push(this.state.getWSData);
                });
                state.newApplicationData.webServices =
                  state.selectedWebServices;
                this.setState(state);
              }}

然后我发现了另一个问题:即使我选择了两个不同的选项,所选选项的列表也只会得到一个重复的选项??? !!!

© www.soinside.com 2019 - 2024. All rights reserved.