Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  47] [ 5]  / answers: 1 / hits: 14576  / 4 Years ago, tue, june 30, 2020, 12:00:00

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 accomodate 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 coming twice. Can anyone please help me with it


More From » arrays

 Answers
2

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


[#3330] Saturday, June 27, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
;