2012-09-12 139 views
0

看着jQuery UI自動完成:http://jqueryui.com/demos/autocomplete/並改變它以符合我的要求,我遇到了一些問題。jQuery UI自動完成 - 修改問題

如果您查看鏈接提供的默認列表,其中一個選項是「ActionScript」,並且如果鍵入「Sc」,則表示「ActionScript」,在我的情況下這不適用。

我只希望它提示 「動作腳本」,例如,如果用戶鍵入:

  • 一個
  • AC
  • ACTI
  • 的Actio
  • 行動
  • 動作
  • ActionSc
  • ActionScr
  • ActionScri
  • ActionScrip
  • 的ActionScript

「動作腳本」 僅僅是一個例子,但它跨越獲取點。

看着jQuery用戶界面自動完成代碼中的提示功能:

_suggest: function(items) { 
     var ul = this.menu.element 
      .empty() 
      .zIndex(this.element.zIndex() + 1); 
     this._renderMenu(ul, items); 
     // TODO refresh should check if the active item is still in the dom, removing the need for a manual deactivate 
     this.menu.deactivate(); 
     this.menu.refresh(); 

     // size and position menu 
     ul.show(); 
     this._resizeMenu(); 
     ul.position($.extend({ 
      of: this.element 
     }, this.options.position)); 

     if (this.options.autoFocus) { 
      this.menu.next(new $.Event("mouseover")); 
     } 
    }, 

我似乎無法找到部分縮小了選擇。有人能指引我朝着正確的方向嗎?我正在使用最新的穩定版本。

回答

1
function hackAutocomplete(){ 

    $.extend($.ui.autocomplete, { 
     filter: function(array, term){ 
      var matcher = new RegExp("^" + term, "i"); 

      return $.grep(array, function(value){ 
       return matcher.test(value.label || value.value || value); 
      }); 
     } 
    }); 
} 

hackAutocomplete(); 

找到了解決它的代碼。