jQuery autocomplete子菜单(在unordered-list中创建unordered-list)

时间:2016-10-20 09:07:04

标签: javascript jquery jquery-ui autocomplete


我有一个jQuery自动完成问题。在keydown上,所选项目不是“Item1”,它将是包含span和ul的完整无序列表。

<ul>
  <li>
    <span>Items</span>
    <ul>
      <li><a>Item1</a></li>
      <li><a>Item2</a></li>
    </ul>
  </li>

  <li>
    <span>Cars</span>
    <ul>
      <li><a>Car1</a></li>
      <li><a>Car2</a></li>
    </ul>
  </li>

  <li>
    <span>Test</span>
    <ul>
      <li><a>Test1</a></li>
      <li><a>Test2</a></li>
    </ul>
  </li>
</ul>

问题是:
在keydown上 - &gt; menufocus:ui.item.data(“ui-autocomplete-item”) - &gt; ui.item 未定义(在jquery.ui.js文件中)
menufocus中的ul参数是“项目”(<ul><li><a>Item1</a></li><li>...</li></ul>).的完整列表 我想要的:在keydown上选择Item1,下一个Item2,下一个Car1,Car2等等......

_renderMenu:
$.each( items, function( index, item ) {
...
  if ( item.category != currentCategory ) {
      categoryIndex++;

      //Create "li"s for every category and append a span and the new ul to it.
      var myLi = "<li class='ui-autocomplete-category'><span class='ui-autocomplete-category-head'><i class='" + category.icon + "'></i> " + category.name + "</span></li>";

      var myLi = $(myLi).removeData("item.autocomplete-item");
      myLi.append("<ul class='ui-autocomplete-inner-ul' role='listbox' aria-labelledby='cat" + categoryIndex  + "' id='innerUlCat"+categoryIndex+"' aria-readonly='true'>");

      var myUl = ul.append(myLi);

        currentCategory = item.category;
  }

  var currentUl = $(ul).find("#innerUlCat"+categoryIndex) || ul;

  li = that._renderItemData( currentUl, item );
});


_renderItemData: return this._renderItemOwn( ul, item );


_renderItemOwn:
  return $( "<li></li>" )
    .data( "ui-autocomplete-item", item )
    .append( "<a class='ui-autocomplete-item'>" + item.label + "</a>" )
    .appendTo( ul );

在_renderItemOwn中,我添加了数据“ui-autocomplete-item”,但它不起作用。
有什么解决方案吗?谢谢!

0 个答案:

没有答案
相关问题