Clear dropdown using jQuery Select2

前端 未结 15 2113
情深已故
情深已故 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

    This works for me:

     $remote.select2('data', {id: null, text: null})
    

    It also works with jQuery validate when you clear it that way.

    -- edit 2013-04-09

    At the time of writing this response, it was the only way. With recent patches, a proper and better way is now available.

    $remote.select2('data', null)
    

提交回复
热议问题