2015-04-28 18 views
6

Tôi nhận được lỗi sau khi sử dụng plugin select2 trên initSelection.select2 - lỗi initselection

Error: Uncaught Error: No select2/compat/initSelection là lỗi tôi nhận được.

Hy vọng ai đó giúp tôi phân loại sự cố inistselection.

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

     }); 
    } 
}); 
+0

'$ (". Doctor_id_pat "). Select2 ({});' chọn 2 là gì? – ashkufaraz

+0

Đây là một plugin cho các tùy chọn được chọn. @ashkufaraz –

+0

Không được chấp nhận trong Select2 4.0. Điều này đã được thay thế bằng một tùy chọn khác và chỉ có sẵn trong các bản dựng đầy đủ của Select2. – Hackerman

Trả lời

21

Select2 v3.5.2 sử dụng phương pháp initSelection. Select2 v4 có cách tiếp cận khác.

Để biết thông tin về cách nâng cấp (initSelection và các nội dung khác), hãy xem https://select2.github.io/announcements-4.0.html#removed-initselection.

+1

Thông tin này đã thay đổi thành [liên kết này] (https://select2.org/upgrading/migrating-from-35#removed-the-requirement-of-initselection). – Phiter

Các vấn đề liên quan