因此,這裏是我做過什麼......
在關鍵了,打電話給我的web服務與新詞,然後把結果返回到自動完成。然後結果被緩存。
我也在檢查用戶何時繼續指定的值包含在數組中,以確保它們不會混淆該值。
function setVendorLookup() {
var term = $(this).val().toLowerCase();
if (term.length > 2) {
if (vendors.join(" ").toLowerCase().indexOf(term) == -1) { //some caching
vendors = [];
$().SPServices({
operation: "GetListItems",
listName: "Yellow Pages",
async: false,
CAMLViewFields: "<ViewFields><FieldRef Name='VENDOR_ID'/><FieldRef Name='NAME1'/><FieldRef Name='CITY'/><FieldRef Name='STATE'/></ViewFields>",
CAMLQuery: "<Query><Where><Or><Contains><FieldRef Name='VENDOR_ID' /><Value Type='Text'>" + term + "</Value></Contains>" +
"<Contains><FieldRef Name='NAME1' /><Value Type='Text'>" + term + "</Value></Contains></Or></Where></Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).find("[nodeName='z:row']").each(function() {
vendors.push($(this).attr("ows_VENDOR_ID") + " - " + $(this).attr("ows_NAME1") + ", " + $(this).attr("ows_CITY") + ", " + $(this).attr("ows_STATE"));
});
}
}); //SPServices
}
$(".vendor").autocomplete({
source: vendors,
minLength: 3
});
} else
vendors = [];
}
function validate()
{
if (jQuery.inArray($(".vendor").val(), vendors) == -1) {
myAlert("Validation Error", "Please select a valid vendor");
return false;
}
}
您是否使用jQueryUI自動完成? –
是的,object.autocomplete –