select2-初始化选择错误 [英] select2 - initselection error

查看:118
本文介绍了select2-初始化选择错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

initSelection上使用select2插件时出现以下错误.

I am getting the following error when using select2 plugin on initSelection.

Error: Uncaught Error: No select2/compat/initSelection是我遇到的错误.

希望有人能帮助我解决inistselection问题.

Hope somebody helps me in sorting out the inistselection issue.

JS:

  $(".doctor_id_pat").select2({
    placeholder: "Search Users",
    minimumInputLength: 2,
    ajax: {
        url: "/listallergiesajax",
        dataType: 'json',
        data: function(term) {
            return {
                q: term
            };
        },
        results: function(data, page) {
            return {

                results: $.map(data, function(item) {

                    return {
                        text: item.text,
                        id: item.id
                    }
                })

            };
        },
    },
    initSelection: function(element, callback) {

        $.ajax("/listallergiesajax", {
            dataType: "json"
        }).done(function(data) {

            callback(data.results[0]);

        });
    }
});

推荐答案

Select2 v3.5.2使用initSelection方法. Select2 v4有不同的方法.

Select2 v3.5.2 uses the initSelection method. Select2 v4 has a different approach.

有关如何升级(initSelection和其他内容)的信息,请参见 https://select2. github.io/announcements-4.0.html#removed-initselection .

For information on how to upgrade (initSelection and other stuff) see https://select2.github.io/announcements-4.0.html#removed-initselection.

这篇关于select2-初始化选择错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆