Commit 7b202460 authored by Clement Ho's avatar Clement Ho

Fix ajax bug

parent 98a95633
...@@ -31,18 +31,13 @@ if ( typeof CustomEvent === "function" ) { ...@@ -31,18 +31,13 @@ if ( typeof CustomEvent === "function" ) {
var CustomEvent = require('./custom_event_polyfill'); var CustomEvent = require('./custom_event_polyfill');
var utils = require('./utils'); var utils = require('./utils');
var DropDown = function(list, trigger) { var DropDown = function(list) {
this.hidden = true; this.hidden = true;
this.list = list; this.list = list;
this.trigger = trigger;
this.items = []; this.items = [];
this.getItems(); this.getItems();
this.addEvents(); this.addEvents();
this.initialState = list.innerHTML; this.initialState = list.innerHTML;
if (this.initialState.indexOf('{{') == -1) {
debugger
}
}; };
Object.assign(DropDown.prototype, { Object.assign(DropDown.prototype, {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
require('../window')(function(w){ require('../window')(function(w){
w.droplabAjaxFilter = { w.droplabAjaxFilter = {
init: function(hook) { init: function(hook) {
this.destroyed = false;
this.hook = hook; this.hook = hook;
this.notLoading(); this.notLoading();
...@@ -49,14 +50,16 @@ require('../window')(function(w){ ...@@ -49,14 +50,16 @@ require('../window')(function(w){
} }
this.loading = true; this.loading = true;
this.hook.list.setData([]); this.hook.list.setData([]);
var params = config.params || {}; var params = config.params || {};
params[config.searchKey] = searchValue; params[config.searchKey] = searchValue;
var self = this; var self = this;
this._loadUrlData(config.endpoint + this.buildParams(params)).then(function(data) { this._loadUrlData(config.endpoint + this.buildParams(params)).then(function(data) {
self.hook.restoreInitialState.call(self.hook); if (!self.destroyed) {
self.hook.list.setData.call(self.hook.list, data[0]); self.hook.list.setData.call(self.hook.list, data[0]);
}
self.notLoading(); self.notLoading();
}); });
}, },
...@@ -92,6 +95,8 @@ require('../window')(function(w){ ...@@ -92,6 +95,8 @@ require('../window')(function(w){
clearTimeout(this.timeout); clearTimeout(this.timeout);
} }
this.destroyed = true;
this.hook.trigger.removeEventListener('keydown.dl', this.debounceTriggerWrapper); this.hook.trigger.removeEventListener('keydown.dl', this.debounceTriggerWrapper);
this.hook.trigger.removeEventListener('focus', this.debounceTriggerWrapper); this.hook.trigger.removeEventListener('focus', this.debounceTriggerWrapper);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment