jquery-select2-4 - Select2 4.0 占位符未定义

标签 jquery-select2-4

请帮忙。

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/

相关文章:

javascript - 检查插件是否已在 jQuery 中初始化?

ajax - Select2 4.0.0 无法选择结果

javascript - Aurelia 试图从 Select2 加载 HTML?

jquery-select2 - 在 Select2 事件中获取选中的选项,当可以选择多个选项时

javascript - 没有 AMD 的 Select2 自定义数据适配器

jquery - Select2 4.0.0不支持标签,无法通过ajax调用获取标签项

javascript - Select2 更改删除的 id 值

javascript - select2中手动触发ajax搜索

javascript - select2.js v4.0如何显示ajax数据?

javascript - 选择2。 js v4.0 : how display and format local array data source?