Print list items on autocomplete

Print list items on autocomplete

Hello everybody! I'm trying to print list items on autocomplete search textbox, I know that this is an old issue but I passed a couple of hours in this without success, only <li></li>. I use linq on mvc to get Json data, and jquery to print the related items.

I have in the controller:

  1. return Json( wl, JsonRequestBehavior.AllowGet );

wl is Enumerable<myClass> and it is returned as JsonResult, like this and what I get:


  1. [{"wordName":"Plan de clasificación","wordID":5,"langName":"español"},{"wordName":"Plan de clasification","wordID":6,"langName":"français"}]

This is the JS code on the view:

  1.     $(document).ready(function () {
  2.             searchBox.autocomplete({
  3.                 source: '<%= Url.RouteUrl("WordAjaxSearch") %>',
  4.                 minLength: 3,
  5.                 dataType: 'json',
  6.                 mustMatch: false,
  7.                 antiCache: new Date().getTime(),
  8.                 formatItem: function(row, i, n) {
  9.                     return row.wordName +' - '+ row.langName;
  10.                 },
  11.                 formatResult: function(row){
  12.                     return row.wordID +' - '+ row.wordName +' - '+ row.langName;
  13.                 },
  14.                 parse: function(data) {
  15.                     data = eval(data);
  16.                     var rows = new Array();
  17.  
  18.                     for (var i = 0; i < data.length; i++) {
  19.                         rows[i] = {
  20.                             data: data[i],
  21.                             value: data[i].wordID,
  22.                             result: data[i].wordName
  23.                         };
  24.                     }
  25.                     return rows;
  26.                 }
  27.             });
  28.     });

And with Firebug I can see this:

  1. <ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 84px; left: 749px; display: none; width: 262px;"><li></li><li></li></ul>

There is two <li>, what means it knows that there are items to print, but which?

Any ideas to resolve this issue ? I'll appreciate it!! Thank you!














    • Topic Participants

    • dagof