Tôi đã đoạn mã sau (javascript):Select2 tải dữ liệu bằng ajax không thể chọn bất kỳ tùy chọn
$('#cbxConnections').select2({
minimumInputLength: 0,
multiple: false,
allowClear: true,
placeholder:{
text:"@Diccionario.Connections",
id:" @Diccionario.Connections"
},
ajax:{
url:'@Url.Action("GetActiveConnections","Admin")',
dataType: 'json',
type:'post',
data:function(params){
return {
q: params.term
};
},
processResults: function(data,page){
return {
results: data
};
}
},
escapeMarkup: function (markup) {
return markup;
},
templateResult: function(response){
return '<div>'+response.Name+'</div>';
},
templateSelection: function(response){
return response.Id;
},
id: function(connection){
console.log(connection);
}
});
Đối với phía máy chủ Tôi đang sử dụng ASP MVC 4. Các chọn get dữ liệu sử dụng ajax và đưa ra các tùy chọn nhưng các tùy chọn này không thể chọn được. Đọc bài viết khác, họ mô tả bằng hàm id, nhưng chức năng này appearently desappears vào phiên bản của Select2 Tôi đang sử dụng 2,4
Tôi foolowing ví dụ về ajax trên tài liệu hướng dẫn hiển thị trên github "Đang tải từ xa dữ liệu"
Cảm ơn! đã giúp rất nhiều. – victorkurauchi
Cảm ơn bạn đã giải thích. – KostasC
Hoàn hảo như tôi muốn. Cảm ơn rất nhiều. –