javascript - jquery ui autocomplete displays only first item in db -
am using jquery autocomplete on templete, results autocomplete displays 1 item despite results fetched have more 1 item. shows first item on list!
example:
if have result list ('type1', 'type2', 'type3')
and on autocomplete type 't' displays type1
on drop down!
i newbie in jquery kindly rectify mistakes( if any)
my autocomplete code:
$(".fro").each(function() { $(this).autocomplete({ source : function(request, response) { $.ajax({ serviceurl: '${pagecontext.request.contextpath}/index.htm', datatype: "json", paramname: "fro", delimiter: ",", data : { term : request.term }, success : function(data) { response($.map(data.result, function(item) { $.each(data, function() { return { label : this.fro, value : this.fro } }); })); } }); }, minlength:1 }); });
my response controller looks this:
@requestmapping(value = "/gettags.htm", method = requestmethod.get, headers="accept=*/*") public @responsebody list<searchfiller> gettags(@requestparam("fro") string fro) { return simulatesearchresult(fro); } private list<searchfiller> simulatesearchresult(string fro) { list<searchfiller> data=searchflightdao.fillerlist(); list<searchfiller> result = new arraylist<searchfiller>(); (searchfiller tag : data) { if (tag.getfro().contains(fro)) { result.add(tag); } } return result; }
right answer gets appreciated
let try this:
$(".fro").each(function() { $(this).autocomplete({ source : function(request, response) { $.ajax({ serviceurl: '${pagecontext.request.contextpath}/index.htm', datatype: "json", paramname: "fro", delimiter: ",", data : { term : request.term }, success : function(data) { dataarray = new array(); $.each(data, function() { var t = { label : this.fro, value : this.fro }; dataarray.push(t); }); response(dataarray); } }); }, minlength:1 }); });
Comments
Post a Comment