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:
- return Json( wl, JsonRequestBehavior.AllowGet );
wl is Enumerable<myClass> and it is returned as JsonResult, like this and what I get:
- [{"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:
- $(document).ready(function () {
- searchBox.autocomplete({
- source: '<%= Url.RouteUrl("WordAjaxSearch") %>',
- minLength: 3,
- dataType: 'json',
- mustMatch: false,
- antiCache: new Date().getTime(),
- formatItem: function(row, i, n) {
- return row.wordName +' - '+ row.langName;
- },
- formatResult: function(row){
- return row.wordID +' - '+ row.wordName +' - '+ row.langName;
- },
- parse: function(data) {
- data = eval(data);
- var rows = new Array();
-
- for (var i = 0; i < data.length; i++) {
- rows[i] = {
- data: data[i],
- value: data[i].wordID,
- result: data[i].wordName
- };
- }
- return rows;
- }
- });
- });
And with Firebug I can see this:
- <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!