浏览 3041 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-05-24
下面给出CachedAutocompleter的一种实现: Ajax.CachedAutocompleter = Class.create(); Object.extend(Object.extend(Ajax.CachedAutocompleter.prototype, Autocompleter.Base.prototype), { initialize: function(element, update, url, options, externalToken) { this.baseInitialize(element, update, options); this.options.asynchronous = true; this.options.onComplete = this.onComplete.bind(this); this.options.defaultParams = this.options.parameters || null; this.url = url; this.cache = {}; this.cacheKey = ""; }, getUpdatedChoices: function() { this.cacheKey = this.getToken(); entry = encodeURIComponent(this.options.paramName) + '=' + encodeURIComponent(this.cacheKey); this.options.parameters = this.options.callback ? this.options.callback(this.element, entry) : entry; if(this.options.defaultParams) this.options.parameters += '&' + this.options.defaultParams; if(this.options.parameters) this.cacheKey = this.options.parameters; if(this.cache[this.cacheKey]) { this.updateChoices(this.cache[this.cacheKey]); } else { new Ajax.Request(this.url, this.options); } }, onComplete: function(request) { this.updateChoices(this.cache[this.cacheKey] = request.responseText); } }); 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |