Select2准备好后如何设置值? [英] how to set values when Select2 is ready?
本文介绍了Select2准备好后如何设置值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Select2
是否有任何onLoad
事件,以便我可以设置一些默认值?现在,在Ember的didInsertElement
的帮助下将Select2
添加到Dom
之后,我采取了一些丑陋的技巧:
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 :)
推荐答案
尝试一下,可能会对您有所帮助,
Try this, it may help you,
$(document).ready(function()
{
$("<option value='0'>Default</option>").insertBefore("option:nth-child(1)");
});
这篇关于Select2准备好后如何设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文