I’m trying to set data for my select element but it doesn’t work!
This is my code when i’m trying to set data from another data when i call from an ajax
$(’#pick_language’).select2(‘data’,{id: lang_data.lang_id, name: lang_data.lang_name, image: lang_data.lang_image, selected: true});
console.log($(’#pick_language’).select2(‘data’));
When i log the result it still response nothing!
But i cant adding the option without event trigger just like this:
var select_option = " ‘<option selected value = ‘’+lang_data.lang_id+"’ label = ‘"+lang_data.lang_image+"’ >"+lang_data.lang_name+ ‘< /option>’
$(id)
.empty()
.append(select_option);
Just the below code i can set data option for selected item but it just receive data default like this:
- disabled: false
- element: option
- id: “2”
- selected: true
- text: “English”
- title: “”
- _resultId: “select2-pick_language-result-bgf2-2”
- proto: Object
But i want it like this:
- lang_domain: null
- lang_id: “2”
- lang_image: “data/lang_icon/icon/English-icon.png”
- lang_name: “English”
- lang_path: “en”
Thanks for your time!