twitter-bootstrap 无法使用数据实时搜索 + 多个 jquery 填充引导程序选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27727655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can not populate bootstrap select with data live search + multiple with jquery
提问by Tasaduq H.
I want to populate the following select statement with options gotten from a php code
我想用从 php 代码获得的选项填充以下选择语句
<select name='friends[]' id='friends' class='selectpicker show-tick form-control'
data-live- search='true' multiple>
<!-- options here -->
</select>
my jQuery code
我的 jQuery 代码
$.ajax({
url:'get_togethers.php', //this returns object data
data:'user_id='+user_id,
type:'POST',
datatype:'json',
success:function(data) { //data = {"0":{"id":1,"name":"Jason"},"1":{"id":2,"name":"Will"},"length":2 }
data = JSON.parse(data);
var options;
for (var i = 0; i < data['length']; i++) {
options += "<option value='"+data[i]['id']+"'>"+data[i]['name']+"</option>";
}
$("#friends").append(options);
}
});
Static values inside the select tag show up, but the values added from the ajax function don't. EDIT : If I remove the bootstrap from this, the values show up, but with bootstrap on, they don't show up.
select 标签内的静态值显示出来,但从 ajax 函数添加的值不显示。编辑:如果我从中删除引导程序,则值会显示,但在引导程序打开时,它们不会显示。
回答by Tasaduq H.
$('#friends').selectpicker('refresh');
Is necessary to update the newly added values, which I had missed.
有必要更新我错过的新添加的值。

