Sahin Yanlık Sahin Yanlık - 1 year ago 148
jQuery Question

Select2 can't set multiple value

I am trying to show selected values in select2-jquery component.

var select = $(".select2").select2({
multiple: true,
placeholder: "",
data: z
var selectedValues = $("#sourceValues").val().split(',');

$.each( selectedValues, function(k,v){

sourceValues holds the value e.g : 2,4
And z is array of object that holds id and text as suggested.
I can see values that I liked to so but cant't show the selected values.
Also If I try to run the query on chrome console it works , if I write something like ;


It founds the id number for and select it .

Answer Source


Attached to select - Multi-Valued - Array of the value attributes of the options that should be selected. null for empty.


var selectedValues = $("#sourceValues").val().split(',');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download