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

后端 未结 7 702
夕颜
夕颜 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 19:52

    It's common for other components to be listening to the change event, or for custom event handlers to be attached that may have side effects. Select2 does not have a custom event (like select2:update) that can be triggered other than change. You can rely on jQuery's event namespacing to limit the scope to Select2 though by triggering the *change.select2 event.

    $('#state').trigger('change.select2'); // Notify only Select2 of changes
    

提交回复
热议问题