我爲每個結果返回多個數據。在每個結果中,我都有不同的鏈接,我想通過這些鏈接進行選擇。現在,無論用戶點擊結果的位置,只是將標題放入文本框而不是處理鏈接。jquery ui自動完成 - 操縱結果
$(function() {
function log(message) {
$("<div/>").text(message).prependTo("#log");
$("#log").attr("scrollTop", 0);
}
$.ajax({
url: "links2.xml",
dataType: "xml",
success: function(xmlResponse) {
var data = $("ROW", xmlResponse).map(function() {
return {
value: $("SC_DF_FIELD_1", this).text(),
url: $("SC_DF_FIELD_2", this).text(),
support_url: $("SC_DF_FIELD_3", this).text(),
description: $("SC_DF_FIELD_4", this).text(),
contact: $("SC_DF_PERSON_LINK", this).text()
};
}).get();
$("#birds").autocomplete({
source: data,
minLength: 0
}).data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.value + "<br>" + item.url + "<br>" + item.description + "<br>" + "Support URL: " + item.support_url + "<br>" + "Contact: " + "<a href=http://someurl.whatever?p_id=" + item.contact + ">Test</a>" + "</a>")
.appendTo(ul);
};
}
})
});
所以我希望他們能夠點擊item.url它去那裏,或item.contact它去那裏。
編輯:
這是我試用的formatItem代碼。它並不會對返回的內容產生任何影響。
function formatItem(item, foo, bar, term){
var temp = item.title + '<br /> ' + item.description + '<br />' + '<a href=' + item.url + '>test</a>';
return temp;
}
$.ajax({
url: "links2.xml",
dataType: "xml",
success: function(xmlResponse) {
var data = $("ROW", xmlResponse).map(function() {
return {
value: $("SC_DF_FIELD_1", this).text(),
url: $("SC_DF_FIELD_2", this).text(),
support_url: $("SC_DF_FIELD_3", this).text(),
description: $("SC_DF_FIELD_4", this).text(),
contact: $("SC_DF_PERSON_LINK", this).text()
};
}).get();
$("#birds").autocomplete({
source: data,
minLength: 0,
formatItem: formatItem
})
}
})
});
我嘗試這種方式並沒有對輸出產生影響。現在我只看到價值。我添加了我想要的問題代碼 – specked 2010-09-20 19:27:39
我不認爲formatItem適用於這個較新的自動完成插件。任何其他想法?我正在使用jQuery-ui插件 – specked 2010-09-21 12:24:36