请帮忙。
html:
<select id="select-client" class="form-control" style="width: 350px;"></select>
js:
$("#select-client").select2({
ajax: {
url: _app.url + "finduser",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term
};
},
processResults: function (data) {
return {
results: data
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 2,
templateResult: formatClientRepo,
templateSelection: formatClientRepoSelection,
placeholder: "Enter user name"
});
结果我收到了这个:http://prntscr.com/76jxvi
我发现了很多变种,比如select中的空选项,或者在中写占位符选择 ,但没有。
最佳答案
https://jsfiddle.net/xqhp0z0x/1/
在这个例子中,如果我们删除 || repo.text
来自 formatRepoSelection
不起作用。因为repo.text
是占位符。
附言select2 4.0 不需要清空option
placeholder
的标签在职的
关于jquery-select2-4 - Select2 4.0 占位符未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30302329/