我尝试使用 ajax 填充我的多个 select2,但我没有返回字段。
这是我的 HTML 代码:
<input type="hidden" id="instituicaoSel" tabindex="-1" class="select2-offscreen" value="">
Javascript:
$('#instituicaoSel').select2(
{
placeholder: "Escolha uma ou mais instituições",
minimumInputLength: 1,
width: '100%',
multiple: true,
ajax: {
url: basepath + "perfil/buscarInstituicoes",
dataType: 'json',
quietMillis: 100,
data: function (term, page) {
return {
q: term,
page_limit: 10,
page: page
};
},
results: function (data, page)
{
var more = (page * 10) < data.total;
return { results: data.results, more: more };
},
dropdownCssClass: "bigdrop"
}
});
这是我在 ajax 上的结果:
[{"result":[{"id":"1","text":"Ag\u00eancia Brasileira de Desenvolvimento Industrial"}],"total":1}]
我放在占位符上的值不会显示。
最佳答案
<select id="sel" placeholder="MyPlaceHolder">
<option></option>
<option>Option value</option>
</select>
你需要添加 <option></option>
一个例子http://hromnik.com/web/select2/
和解决方案:http://hromnik.wordpress.com/2012/10/18/select2-placeholder-does-not-work-solution/
关于javascript - select2 多选ajax php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21780445/