【问题标题】:Select2 ajax processing resultsselect2 ajax处理结果
【发布时间】:2017-06-07 14:44:26
【问题描述】:

我正在使用 select2 和 ajax 搜索数据库查询。一切正常,但我有 1 个小问题。

假设我正在查看数据库中的 ID,当我开始写入 select2 ID 时:111 - 找到记录 - 1 行,但我有 2 行,顶部是 111。

这里是javascript:

$(".select2-ajax").select2({
            minimumInputLength: 1,
            tags: [],
            ajax: {
                url: "ajax/" + uri,
                dataType: 'json',
                type: "GET",
                quietMillis: 50,
                data: function (term) {
                    return {
                        q: term.term
                    }
                },
                processResults: function (data) {
                    return {
                        results: data
                    };
                }
            }
        });

结果屏幕:

预期结果:

与图片相同,但没有第一个选项,只有 111

【问题讨论】:

    标签: jquery ajax jquery-select2


    【解决方案1】:

    已解决,是tags: []引起的

    $(".select2-ajax").select2({
                minimumInputLength: 1,
                ajax: {
                    url: "ajax/" + uri,
                    dataType: 'json',
                    type: "GET",
                    quietMillis: 50,
                    processResults: function (data) {
                        return {
                            results: data
                        };
                    },
                    cache: true
                }
            });
    

    【讨论】:

      猜你喜欢
      • 2016-04-12
      • 2016-04-10
      • 2016-09-11
      • 2019-07-13
      • 1970-01-01
      • 2013-06-12
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多