I have the following code (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); } });
For the server side, I use ASP MVC 4. The select command receives data using ajax and displays the parameters, but these parameters are not available for selection. While reading other posts, they describe the use of the id function, but this function clearly disappears in the select2 version that I am using 2.4
I follow the ajax example in the documentation showing on github "Downloading remote data"
javascript jquery ajax jquery-select2 jquery-select2-4
jcvegan Mar 13 '15 at 15:09 2015-03-13 15:09
source share