如何添加显示带描述的较小文本的结果?我在自动完成正在使用的数据数组中有描述。我可以通过使用.result函数并调用item.description
来调用它现在我看到一个清单:
Item1<br />
Item2<br />
Item3<br />
我想拥有它
Item1<br />
description<br />
Item2<br />
description<br />
Item3<br />
description<br />
var results = new Array();
function prep(){
$("#searchbox").autocomplete(results,{
formatItem: function(item) {
return item.title;
}
}).result(function(event, item) {
location.href = item.url;
});
}
$(document).ready(function(){
$.ajax({
type: "GET",
url: "links2.xml",
dataType: "xml",
success: function(xml) {
// Count elements
var count = $(xml).find('ROW').length;
// Create Array of correct length
//window.results = new Array(count);
// Set array variable
var num_row = 0;
//data string
var datastring = "";
//start of find block
$(xml).find('ROW').each(function() {
var title = $(this).find('SC_DF_FIELD_1').text();
var url = $(this).find('SC_DF_FIELD_2').text();
var support_url = $(this).find('SC_DF_FIELD_3').text();
var description = $(this).find('SC_DF_FIELD_4').text();
var contacts = $(this).find('SC_DF_FIELD_5').text();
//clean up xml variables
url = url.substring(url.indexOf('>') + 1, url.indexOf('/a') - 1);
support_url = support_url.substring(support_url.indexOf('>') + 1, support_url.indexOf('/a') - 1); /*need to clean up contacts search later */
results[num_row] = {'title': title, 'url': url, 'support_url': support_url, 'description': description, 'contacts': contacts};
num_row++
// $('<div class="items"></div>').html('<a href="' + url + '">' + title + '</a>').appendTo('#page-wrap');
});
//end of find block
prep();
}
});
});
</script>
</head>
<body>
<div id="page-wrap">
<FORM autocomplete="off"><INPUT id="searchbox" type="text"/>
</FORM></DIV>
</body>
</html>
答案 0 :(得分:0)
我想通了
将描述添加到return语句中。 DOH!