【问题标题】:Select2 Show Currently Searched ValueSelect2 显示当前搜索的值
【发布时间】:2017-03-02 08:03:46
【问题描述】:

我正在使用 Selec2 框架通过 ajax 调用来执行此操作,我已在我的项目中成功实现了此功能,但是为什么当输入值进行搜索时,它会将当前搜索值显示为可选选项,即使没有结果,我也想不要隐藏这一点。有什么建议吗?谢谢

显示当前搜索值并且它是可选的:

即使没有结果:

HTML:

<select style='width:100%;' id='select-employee'></select>

JS:

$("#select-employee").select2({
    theme: "bootstrap",
    placeholder: "Select employee...",
    minimumInputLength: 1,
    tags: [],
    ajax: {
        url: "getEmployee.php",
        dataType: "json",
        type: "POST",
        delay: 250,
        data: function(params) {
            return {
                term: params.term,
                page: params.page
            };
        },
        processResults: function(data, params) {
            params.page = params.page || 0;
            return {
                results: data.items,
                pagination: {
                    more: (data.page == "1" ? true : false)
                }
            };
        },
        cache: true
    }
});

【问题讨论】:

    标签: javascript jquery twitter-bootstrap select2


    【解决方案1】:

    你好,因为你必须将标签填充为false,尝试将[]更改为false

    $("#select-employee").select2({
      theme: "bootstrap",
      placeholder: "Select employee...",
      minimumInputLength: 1,
      tags: false,
      ajax: {
        url: "getEmployee.php",
        dataType: "json",
        type: "POST",
        delay: 250,
        data: function(params) {
            return {
                term: params.term,
                page: params.page
            };
        },
        processResults: function(data, params) {
            params.page = params.page || 0;
            return {
                results: data.items,
                pagination: {
                    more: (data.page == "1" ? true : false)
                }
            };
        },
        cache: true
      }
    });
    

    【讨论】:

    • 它有效,谢谢老兄:D 对不起这个问题,但我很沮丧,我按照 select2 文档中的说明操作,但什么也没找到,我不知道在 google 中搜索的查询
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2017-01-24
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多