javascript - Mapping an array of strings to results in Select2 -
i've got json string
{"plaats":["rottevalle","rotterdam"]}
and "rottevalle , rotterdam" item in selectbox select2
i've got code.
$("#plaats").select2({ minimuminputlength: 3, tags: [], ajax: { url: 'plaatsen.php', datatype: 'json', delay: 250, data: function (params) { return { q: params.term, // search term page: params.page }; }, processresults: function (data) { return { results: $.map(data, function(obj) { return { id: obj.plaats, text: obj.plaats }; }) }; } } });
problem don't understand how plaats
data within processresults
.
the issue passing full response $.map
instead of plaats
key of that.
$("#plaats").select2({ minimuminputlength: 3, tags: [], ajax: { url: 'plaatsen.php', datatype: 'json', delay: 250, data: function (params) { return { q: params.term, // search term page: params.page }; }, processresults: function (data) { return { results: $.map(data.plaats, function(obj) { return { id: obj, text: obj }; }) }; } } });
Comments
Post a Comment