mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-25 22:27:39 +00:00
Added canUseCache: function option.
Check if this query can be autocompleted from cache, without ajax request. Usage (directory autocomplete, do ajaxs only if "/" has been typed): $(selector).autocomplete({ ... canUseCache: function(query) { return query.length == 0 || query[query.length - 1] != "/"; }, ... });
This commit is contained in:
parent
5db721d7b6
commit
3cb1c471df
@ -73,6 +73,7 @@
|
|||||||
tabDisabled: false,
|
tabDisabled: false,
|
||||||
dataType: 'text',
|
dataType: 'text',
|
||||||
currentRequest: null,
|
currentRequest: null,
|
||||||
|
canUseCache: null,
|
||||||
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
|
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
|
||||||
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
|
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
|
||||||
},
|
},
|
||||||
@ -434,18 +435,24 @@
|
|||||||
if(this.currentRequest != null) {
|
if(this.currentRequest != null) {
|
||||||
this.currentRequest.abort();
|
this.currentRequest.abort();
|
||||||
}
|
}
|
||||||
|
if ($.isFunction(options.canUseCache) && options.canUseCache(q) && that.cachedData) {
|
||||||
|
that.processResponse(that.cachedData, q);
|
||||||
|
options.onSearchComplete.call(that.element, q);
|
||||||
|
} else {
|
||||||
this.currentRequest = $.ajax({
|
this.currentRequest = $.ajax({
|
||||||
url: serviceUrl,
|
url: serviceUrl,
|
||||||
data: options.ignoreParams ? null : options.params,
|
data: options.ignoreParams ? null : options.params,
|
||||||
type: options.type,
|
type: options.type,
|
||||||
dataType: options.dataType
|
dataType: options.dataType
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
|
that.cachedData = data;
|
||||||
that.processResponse(data, q);
|
that.processResponse(data, q);
|
||||||
options.onSearchComplete.call(that.element, q);
|
options.onSearchComplete.call(that.element, q);
|
||||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||||
options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown);
|
options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
isBadQuery: function (q) {
|
isBadQuery: function (q) {
|
||||||
|
Loading…
Reference in New Issue
Block a user