how to set values when Select2 is ready?

六眼飞鱼酱① 提交于 2019-12-12 17:48:49

问题


Does Select2 have any onLoad event so that I can set some default value? Now I resorted to some ugly trick after Select2 is added to the Dom with the help of Ember's didInsertElement:

`setTimeout(function() {$select.select2('val', id).trigger('change'), 500});

I'm pretty sure there is a better solution out there :)


回答1:


Try this, it may help you,

$(document).ready(function() 
{
  $("<option value='0'>Default</option>").insertBefore("option:nth-child(1)");
});


来源:https://stackoverflow.com/questions/17810234/how-to-set-values-when-select2-is-ready

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!