Clear dropdown using jQuery Select2

前端 未结 15 2147
情深已故
情深已故 2020-11-28 11:35

I\'m trying to programmatically clear a drop down using the fantastic Select2 library. The drop down is dynamically filled with a remote ajax call using the Select2 qu

15条回答
  •  心在旅途
    2020-11-28 12:26

    From >4.0 in order to really clean the select2 you need to do the following:

    $remote.select2.val('');
    $remote.select2.html('');
    selectedValues = []; // if you have some variable where you store the values
    $remote.select2.trigger("change");
    

    Please note that we select the select2 based on the initial question. In your case most probably you will select the select2 in a different way.

    Hope it helps.

提交回复
热议问题