Help with handling jQuery autocomplete result?
I need to split the string result of the autocomplete plugin. I know how to split the string and what not, but don't know 开发者_如何学运维how to do it in context of the plugin. Here is what I have thus far. Any help would be greatly appreciated:
<script type="text/javascript">
$(document).ready(function() {
$('.divAutoComplete').autocomplete("LookupCodes.aspx?type=IC", { mustMatch: true });
});
</script>
EDIT: I have changed it as follows and now Firebug is barking at me, saying that "value.replace is not a function" (the error is in the plugin script). Not sure what I'm doing wrong:
<script type="text/javascript">
$(document).ready(function() {
$('.divAutoComplete').autocomplete("LookupCodes.aspx?type=IC", { mustMatch: true, formatItem: formatItem });
});
function formatItem(row) {
var a = row[0].toString().split('--');
return a;
}
This is how I did it:
/********************************************************************************
Search Functions
********************************************************************************/
function setSearchAutoComplete()
{
$("#txtSearchCustomer").autocomplete
("DataFiles/Search.ashx",
{
formatItem: formatItem,
selectFirst: true,
minChars: 3,
max: 50,
cache: false
}
);
$("#txtSearchCustomer").result(findValueCallback);
}
function findValueCallback(event, data, formatted)
{
$("#spnFirst").empty().html(data[0]);
$("#spnLast").empty().html(data[1]);
$("#spnAddress").empty().html(data[2]);
}
function formatItem(row)
{
return "<u>" + row[0] + "</u> <em>" + row[1] + "</em>";
}
HTH
In my instance, I was trying to use autocomplete on a list item instead of an input element.
精彩评论