I'm sending the response data of two attributes as below:
response["gender"] = 'Male' #Or whatever is the value from database
response["gender_choices"] = [
[, '-----------------'],
['MALE', 'Male'],
['FEMALE', 'Female'],
['OTHERS', 'Others']
]
I am using select2. My present code is as below:
$('.element-form#gender').select2({
placeholder: "Gender",
data: $.map(response.gender_choices, function(obj){
obj.value = obj[0];
obj.text = obj[1];
return obj.value, obj.text;
}
),
});
But it is adding the obj.text values to both option value and text.
What I want is to add the value of obj.value to option value and obj.text to text.
Also how can I make the response["gender"] option selected value?