如何重新填充select2结果

约翰·克里斯蒂安·德·查韦斯

再会,

我正在为我的项目使用Select2插件。我在收件人文本的电子邮件功能中使用了它。最初,一旦用户键入内容,它将从数据库中获取内容,然后将其添加到my的内部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 -->

还有我下面的脚本示例

$(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
                }
          });
      });
约翰·克里斯蒂安·德·查韦斯

我使用了select2 ajax选项。它可以使用ajax方法获取数据。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章