我已經花了最近幾個小時閱讀YUI文檔和代碼,但無法使其工作。無法讓YUI自動完成工作
我的遠程數據源是XML。我有一個本地代理來檢索遠程數據。
我已經通過Firebug確認,當我在輸入字段中輸入時,請求正在發送並且數據正在返回。但是,我配置來保存結果的div沒有被寫入。在檢查DOM時,YUI使用它的用於保存結果的html結構填充我的div,但沒有內容。
它經常被記錄爲調用函數「formatResult」來過濾結果。但是,這永遠不會發生。我通過在函數中使用alert()來測試它。
我不知道什麼不是發生。以下是我的XML格式和我的代碼。我通過YUI加載器加載數據源和自動完成依賴關係。
<div id="auto-search">
<input type="text" id="auto-search-input" value=""/>
<div id="auto-search-results"></div>
</div>
YAHOO.example.auto = function() {
var searchDataSource = new YAHOO.util.XHRDataSource("http://localhost/insidersearchproxy.php");
searchDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
searchDataSource.responseSchema = {
resultNode : "RelatedResult",
fields: [ "rid","rtype", "title", "thumbURL" ]
}
var autosearch = new YAHOO.widget.AutoComplete("auto-search-input","auto-search-results", searchDataSource);
autosearch.generateRequest = function(sQuery) {
return "?q="+sQuery;
};
autosearch.resultsTypeList = false; // pass data as an object
autosearch.applyLocalFilter = true; // pass results thru filter
autosearch.formatResult = function(oResultData, sQuery, sResultMatch) {
var sMarkup = (sResultMatch) ? sResultMatch : "";
return sMarkup;
};
return {
searchDataSource: searchDataSource,
autosearch: autosearch
};
}();
<list>
<RelatedResult>
<rid>2014</rid>
<rtype>Celebrity</rtype>
<title>Adam Brody</title>
<thumbURL>http://cm1.theinsider.com/media/0/52/65/wenn1302741.50.jpg</thumbURL>
</RelatedResult>
<RelatedResult>
<rid>2776</rid>
<rtype>Celebrity</rtype>
<title>Adam Sandler</title>
<thumbURL>http://cm1.theinsider.com/media/0/49/95/wenn1198212.50.jpg</thumbURL>
</RelatedResult>
<RelatedResult>
<rid>3084</rid>
<rtype>Celebrity</rtype>
<title>Bryan Adams</title>
<thumbURL>http://cm1.theinsider.com/media/0/1/46/RoomSer4.50.jpg</thumbURL>
</RelatedResult>
<RelatedResult>
<rid>5747</rid>
<rtype>Celebrity</rtype>
<title>Amy Adams</title>
<thumbURL>http://cm1.theinsider.com/media/0/56/87/wenn5095565.50.jpg</thumbURL>
</RelatedResult>
<RelatedResult>
<rid>6572</rid>
<rtype>Celebrity</rtype>
<title>Adam Richard</title>
<thumbURL>http://cm1.theinsider.com/media/0/7/97/Adam_Richard_small.50.jpg</thumbURL>
</RelatedResult>
<RelatedResult>
<rid>9001</rid>
<rtype>Celebrity</rtype>
<title>Adam Goldberg</title>
<thumbURL>http://cm1.theinsider.com/media/0/80/15/91969967.50.jpg</thumbURL>
</RelatedResult>
<RelatedResult>
<rid>30897</rid>
<rtype>Celebrity</rtype>
<title>Adam Rothenberg</title>
<thumbURL>http://cm1.theinsider.com/media/0/99/86/ex_bio_adam.50.jpg</thumbURL>
</RelatedResult>
<RelatedResult>
<rid>58009</rid>
<rtype>Celebrity</rtype>
<title>Adam Lambert</title>
<thumbURL>http://cm1.theinsider.com/media/0/361/95/271363.50.jpg</thumbURL>
</RelatedResult>
</list>