我已經在YUI中實現了自動完成功能。 但我想要做的是,當用戶選擇一個建議,形式應與建議YUI自動提交完整建議
<script>
YUI().use('array-extras','autocomplete','autocomplete-highlighters',function(Y) {
function locateModules(response) {
var results = [];
if(response && response.dimensions){
for (var i = 0; i < response.dimensions.length; i++) {
if(response.dimensions[i] && response.dimensions[i].refinements){
for (var j = 0; j < response.dimensions[i].refinements.length; j++) {
if(response.dimensions[i].refinements[j].refinements){
results = results.concat(response.dimensions[i].refinements[j].refinements)
}
results.push(response.dimensions[i].refinements[j]);
}
}
}
}
return Y.Array.filter(results, function(result) {
//some other conditions
return true;
});
}
Y.one('#searchId').plug(Y.Plugin.AutoComplete, {
resultHighlighter : 'phraseMatch',
resultListLocator : locateModules,
resultTextLocator : 'name',
source : '<%=autoCompleteURL%>&<portlet:namespace/>q={query}'
});
});
</script>
一起提交,我有形式這樣
<form ...>
<input name="searchId" id="searchId" placeholder="Search Product" />
......
</form>
- 的自動建議正在妥善處理。但是,當用戶選擇 建議,應在形式
- 提交的還有另一種自動意見箱,實際上得到與用戶什麼 是打字建議如下圖所示
來自YUI建議的Orange color
文本/類別,我如何顯示它們如圖所示。 [片,藥盒&封面是從YUI來]
[This](http://stackoverflow.com/questions/4713987/yui-autocomplete-events-how-to)幫助我希望。該文檔說當用戶選擇一個建議時會觸發「select」事件。 –
@sivatumma,謝謝你真的幫我提交了關於選擇建議的表單。但是,如何根據我的帖子顯示搜索建議? – Reddy