我有以下代码(javascript):
$('#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);
}
});
对于服务器端,我使用的是ASP MVC 4.使用ajax选择获取数据并渲染选项,但此选项不可选 . 阅读其他帖子,他们描述使用id函数,但是这个函数显然在select2的版本上消失我正在使用2.4
我在github "Loading remote data" 上显示的文档中愚弄了ajax的例子
1 回答
如果你的ajax响应没有 id 和 text 属性,你应该修复它们的客户端
这是版本4.0的要求(不知道为什么)