How do I change selected value of select2 dropdown with JqGrid?

后端 未结 16 978
遥遥无期
遥遥无期 2020-11-27 10:27

I\'m using Oleg\'s select2 demo, but I am wondering whether it would be possible to change the currently selected value in the dropdown menu.

For example, if the fou

16条回答
  •  长情又很酷
    2020-11-27 11:06

    You have two options - as @PanPipes answer states you can do the following.

    $(element).val(val).trigger('change');
    

    This is an acceptable solution only if one doesn't have any custom actions binded to the change event. The solution I use in this situation is to trigger a select2 specific event which updates the select2 displayed selection.

    $(element).val(val).trigger('change.select2');
    

提交回复
热议问题