Sahin Yanlık Sahin Yanlık - 9 months ago 89
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 .



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(',');