Select2 4.0占位符未定义(Select2 4.0 placeholder undefined)

编程入门 行业动态 更新时间:2024-10-21 13:27:37
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

更多推荐

本文发布于:2023-07-14 20:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未定义   placeholder   undefined

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!