I am using the Jquery based autocomplete module .I have a small doubt in its functionality. My autocomplete 开发者_开发知识库data is available in a local JavaScript variable. The autocomplete works fine, but whenever I update this local javascript variable it still uses the old data. Does this module cache the data? How can we go about fixing this.
The jQuery UI autocomplete does not have caching built in however it does make an internal copy of the source for the lookup values. In order to update this internal source you need to call the setter on the source parameter like so:
var source = [
"dog",
"cat"
];
var myAutocomplete = $("#myid").autocomplete({
source: availableTags
});
//Add new items after autocomplete init
source.push("mouse");
//Update the autocomplete with the modified source
myAutocomplete.autocomplete("option", "source", source);
Here is a jsfiddle with it working:
http://jsfiddle.net/enXYS/
Your browser is probably caching the JS file. Ctrl f5 to force clean the browsers cache.
Try smth like: $('input#necessary_input').flushCache();
.
Updated (according to the comments below):
Ok. What about simple recreating of autocomplete (firstly remove it, then create with autocomplete
function and new data)?
精彩评论