2009-07-13 37 views
0

我打獵YUI自動完成的實現,我遇到了這個腳本從網站asklaila.com -YUI自動完成例題

<script type="text/JavaScript"> 
    YAHOO.example.ACJson = new function() { 
     this.oACDS = new YAHOO.widget.DS_XHR("/AutoComplete.do", 
      ["Suggestions[0].Results","Name"]); 

     this.oACDS.queryMatchContains = true; 
     this.oACDS.scriptQueryAppend = "city=Mysore"; // Needed for YWS 
     function fnCallback(e, args) { 
      document.searchForm.where.focus(); 
      acSelected = true; 
      return false; 
     } 

     this.oAutoComp = new YAHOO.widget.AutoComplete('what','whatContainer', this.oACDS); 
     this.oAutoComp.itemSelectEvent.subscribe(fnCallback); 
     this.oAutoComp.formatResult = function (oResultItem,sQuery) { 
      return oResultItem[0]; 
     } 

     this.oAutoComp.queryDelay = 0; 
     this.oAutoComp.useIFrame = true; 
     this.oAutoComp.prehighlightClassName = "yui-ac-prehighlight"; 
     this.oAutoComp.minQueryLength = 2; 
     this.oAutoComp.autoHighlight = false; 
     this.oAutoComp.textboxFocusEvent.subscribe(function() { 
      this.oAutoComp.sendQuery(""); 
     }); 

     this.oAutoComp.doBeforeExpandContainer = function(oTextbox, oContainer, sQuery, aResults) { 
      var pos = YAHOO.util.Dom.getXY(oTextbox); 
      pos[1] += YAHOO.util.Dom.get(oTextbox).offsetHeight + 2; 
      YAHOO.util.Dom.setXY(oContainer,pos); 
      return true; 
     }; 
    } 
</script> 

據implenting YUI的自動完成下拉。我想了解的是,這是什麼

this.oACDS = new YAHOO.widget.DS_XHR("/AutoComplete.do", ["Suggestions[0].Results","Name"]); 

確實和它對代碼的影響。

回答

0

this.oACDS = new YAHOO.widget.DS_XHR(「/ AutoComplete.do」,[「Suggestions [0] .Results」,「Name」]);

在每次按鍵時,它都會從服務器獲取json響應,並使用它來填充自動填充下拉列表。 json包含的名稱僅在此節點上顯示,「name」字段中的「Suggestions [0] .Results」。

如果您有任何問題,請提前詢問。我爲asklaila.com寫了一段代碼

0

我打獵 YUI自動完成功能的實現和我遇到 這個腳本來......

爲什麼不來看看YUI自動完成頁面進行深入的例子。

Yahoo! UI Library: AutoComplete

+0

我確實看到了,並且實現了我自己的。我想知道如何在我發佈的鏈接上工作,或者至少了解它使用的是哪種方法。 你有使用YUI的想法嗎?你能幫我澄清一些疑問嗎? – 2009-07-13 11:20:06

1

這是YUI使用的是舊版本,但它是建立在自動完成從讀取的數據源。這個特定的數據源使用XHR從服務器請求信息來填充自動填充字段。

"Autocomplete.do" 

是每次在用戶輸入時自動完成觸發時由DataSource查詢的相對URL。

["Suggestions[0].Results","Name"] 

是,告訴數據源如何從請求URL解析結果responseSchema。它需要知道如何解析數據,以便能夠顯示正確的結果。

+0

所以這autocomplete.do駐留在主機的網站本身?也。所以模式的名字是「Suggestions [0] .Results」,查詢的字段是「Name」是否正確? – 2009-07-14 02:57:44

+0

是的。我真的建議你看看YUI站點上的例子,而不是嘗試使用一些隨機的野外版本。這些例子很棒,應該對你有用。 – Tivac 2009-07-14 17:43:19