Jquery 如何重新填充select2结果
你好 我正在为我的项目使用Select2插件。我在收件人文本的电子邮件功能中使用了它。首先,一旦用户键入它将从数据库中获取的内容,然后它将在myJquery 如何重新填充select2结果,jquery,jquery-select2,select2,Jquery,Jquery Select2,Select2,你好 我正在为我的项目使用Select2插件。我在收件人文本的电子邮件功能中使用了它。首先,一旦用户键入它将从数据库中获取的内容,然后它将在myselect中添加新选项。我的问题是如何重新填充select2的结果,而不是显示无结果 下面是我的html代码 <div class="form-group" id="div_select2"> <select class="form-control select2" id="select2_email" multiple="
select
中添加新选项。我的问题是如何重新填充select2的结果,而不是显示无结果
下面是我的html代码
<div class="form-group" id="div_select2">
<select class="form-control select2" id="select2_email" multiple="multiple" data-placeholder="Select a Group" style="width: 100%;">
<option></option>
<option value="group" data-id="1">Pulse Asia Group</option>
<option value="group" data-id="2">Unite Group</option>
<option value="group" data-id="3">RCBC Group</option>
</select>
</div><!-- /.form-group -->
脉冲亚洲集团
联合集团
RCBC集团
下面是我的脚本示例
$(document).ready(function(){
$('#div_select2').on('keyup','.select2-search__field',function(){
keyme = $(this);
$(this).attr('added','current');
console.log($('#select2-select2_email-results li').eq(0));
if( typeof $('#select2-select2_email-results li').eq(0).attr('id') == 'undefined'){ //select2 no result
l = '<option class="added-opt" value="group" data-id="">'+$(this).val()+'</option>';
$('#select2_email').append(l);
//i want to trigger the repopulate of results here so the user can choose dynamic results
}
});
});
$(文档).ready(函数(){
$('div_select2')。在('keyup','select2-search_字段',函数()上{
keyme=$(这个);
$(this.attr('added','current');
console.log($('#select2-select2_email-results li').eq(0));
if(typeof$('#select2-select2_email-results li').eq(0).attr('id')='undefined'){//select2无结果
l=''+$(this.val()+'';
$(“#选择2_电子邮件”)。附加(l);
//我想在这里触发结果的重新填充,以便用户可以选择动态结果
}
});
});
我使用了select2ajax选项。它可以使用ajax方法获取数据