how to refresh Select2 dropdown menu after ajax loading different content?

后端 未结 7 686
夕颜
夕颜 2020-12-08 19:42

I\'m using Select2 in a combination of dropdown menus. I have one menu for \"Countries\" and one for \"States/Provinces\". Depending on the country that is chosen, the \"Sta

7条回答
  •  温柔的废话
    2020-12-08 20:11

    Got the same problem in 11 11 19, so sorry for possible necroposting. The only what helped was next solution:

    var drop = $('#product_1');   // get our element, **must be unique**;
    var settings = drop.attr('data-krajee-select2');  pick krajee attrs of our elem;
    var drop_id = drop.attr('id');  // take id 
    settings = window[settings];  // take previous settings from window;
    drop.select2(settings);  // initialize select2 element with it;
    $('.kv-plugin-loading').remove(); // remove loading animation;
    

    It's, maybe, not so good, nice and precise solution, and maybe I still did not clearly understood, how it works and why, but this was the only, what keeps my select2 dropdowns, gotten by ajax, alive. Hope, this solution will be usefull or may push you in right decision in problem fixing

提交回复
热议问题