How to set selected value of jquery select2?

后端 未结 28 1422
野趣味
野趣味 2020-11-30 00:00

This belong to codes prior to select2 version 4

I have a simple code of select2 that get data from ajax



        
28条回答
  •  长情又很酷
    2020-11-30 00:43

    if you are getting your values from ajax, before calling

    $("#select_location_id").val(value);
    $("#select_location_id").select2().trigger('change');

    confirm that the ajax call has completed, using the jquery function when

    $.when(ajax1(), ajax2(), ajax3(), ajax4()).done(function(a1, a2, a3, a4){
          // the code here will be executed when all four ajax requests resolve.
          // a1, a2, a3 and a4 are lists of length 3 containing the response text,
          // status, and jqXHR object for each of the four ajax calls respectively.
        }); 
    as described here [Wait until all jQuery Ajax requests are done?

提交回复
热议问题