admin管理员组

文章数量:1321241

I Am using multiselect dropdown, what i want is whatever i've selected in dropdown to send it to the server by calling an api which contains query param to acodate these dropdown result. I have made an array of selected items. Array(3) [ "IphoneXR", "Nokia", "Samsung" ] I want this array to get pass to below url like this: http://localhost:8080/details?dropdown=IphoneXR,Nokia,Samsung. With my approach i am ending up with this: http://localhost:8080/details?dropdown[]=IphoneXR&dropdown[]=Nokia. I am not sure why dropdown[] is ing twice. Can anyone please help me with it

I Am using multiselect dropdown, what i want is whatever i've selected in dropdown to send it to the server by calling an api which contains query param to acodate these dropdown result. I have made an array of selected items. Array(3) [ "IphoneXR", "Nokia", "Samsung" ] I want this array to get pass to below url like this: http://localhost:8080/details?dropdown=IphoneXR,Nokia,Samsung. With my approach i am ending up with this: http://localhost:8080/details?dropdown[]=IphoneXR&dropdown[]=Nokia. I am not sure why dropdown[] is ing twice. Can anyone please help me with it

Share Improve this question asked Jun 30, 2020 at 9:55 SinghSingh 2072 gold badges5 silver badges20 bronze badges 3
  • 1 Hello! Please share the code snippet that is causing issue for the munity to be able to contribute. – Dhruv Shah Commented Jun 30, 2020 at 9:57
  • This will be helpful to you [stackoverflow./questions/1763508/… – Jay Parmar Commented Jun 30, 2020 at 10:01
  • thanks @JayParmar, link is very useful.it worked – Singh Commented Jun 30, 2020 at 10:18
Add a ment  | 

2 Answers 2

Reset to default 3

Convert the array into string and pass the value in query param.

multiSelectHandler = (option) => {
    const details = option.selectedItems;
   const stringData =  details.map(({value}) => `${value}`).join(',');
   console.log(stringData);
  };

Array: Details: Output in console

0: Object { value: "Iphone", label: "Iphone" }
    ​1: Object { value: "Samsung", label: "Samsung"}

After converting into string:Output in console, Iphone,Samsung

Now pass this stringData in queryparam

If you are passing it directly to a url via the form actions it will sent it in the url as this: index.html?cars=saab&cars=opel&cars=audi

Try handling the form via js like this How handle multiple select form in ReactJS

本文标签: javascriptHow to pass an array in query parameter reactjsStack Overflow