select2 - initselection error

你离开我真会死。 提交于 2019-12-10 13:12:10

问题


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

Error: Uncaught Error: No select2/compat/initSelection is the error I am getting.

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]);

        });
    }
});

回答1:


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

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



来源:https://stackoverflow.com/questions/29919108/select2-initselection-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!