Populate select2 with JSON after init doesnt work
问题 I'm trying to populate a select2 element with a JSON array; but I can't get it. I have the next array: data = [{"id":"Foo","text":"Foo"},{"id":"Bar","text":"Bar"}] And I initialize select2 as follow: $("#selectElement").select2(); I use the next code to populate: $('#selectElement').select2('data', data, true); But doesnt work and I dont know why. Someone can help me? EDIT: I need to populate after the init of select2 (I receive JSON from AJAX) My intention is populate the select2 of my