javascript - jquery-ui autocomplete ajax, isusse in succes -
i have 1 autocomplete element in page, use json request data, cant see ui.
i made test in past, default fuctionaly
$(function() { var availabletags = [ "actionscript", "applescript", "asp", "basic", "c", "c++", "clojure", "cobol", "coldfusion", "erlang", "fortran", "groovy", "haskell", "java", "javascript", "lisp", "perl", "php", "python", "ruby", "scala", "scheme" ]; $( "#tags" ).autocomplete({ source: availabletags }); });
but, i chage structure of data
$(function () { var availabletags = [ {"label":"one label", "value":"one value", "id":1}, {"label":"2 label", "value":"2", "id":2}, {"label":"3 label", "value":"3", "id":3}, {"label":"4 label", "value":"etc", "id":4} ]; $("#tags").autocomplete({ source: availabletags, select: function(event, ui) { $('#id_element').val(ui.item.id);//for example } }); });
i did work event select, want data json
$("#inputskills").autocomplete({ source: function( request, response ) { $.ajax({ url: '/' + getpathstr() + '/skills/1?term='+request.term, datatype: "json", data: { featureclass: "p", style: "full", maxrows: 12, name_startswith: request.term }, success: function( data ) { //alert(json.stringify(data)); response( $.map( data, function( item ) { //alert(json.stringify(item)); alert(item.value+' - '+item.label+ ' - ' + item.id ); return{ label: item.label, value: item.id } })); } }); }, select .....
my service return correct data, when show data alert function, correct data, but, autocomplete no work, no sohw data, tried change return code, not make work
i change
return { label: item.label, id: item.id, value: item.value }
or
return item;
but still can not, me please.
Comments
Post a Comment