Select2 4.0占位符未定义(Select2 4.0 placeholder undefined)
请帮忙。
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中的空选项,或者在select中写占位符,但没有。
Please, help.
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" });And as result I've received this: http://prntscr.com/76jxvi I found many variants, such as empty option in select, or write placeholder in select, but nothing.
最满意答案
https://jsfiddle.net/xqhp0z0x/1/
在这个例子中,如果我们删除|| repo.text 来自formatRepoSelection || repo.text它将无法正常工作。 因为repo.text是占位符。
PS select2 4.0不需要为placeholder工作清空option标签
https://jsfiddle.net/xqhp0z0x/1/
in this example if we delete || repo.text from formatRepoSelection it will not work. Because the repo.text is placeholder.
P.S. select2 4.0 do not need to empty option tag for placeholder working
更多推荐
发布评论