Created
October 16, 2015 18:40
-
-
Save gazlu/452860ddb9da4089c153 to your computer and use it in GitHub Desktop.
Custom ajax implementation with Select2 - angular, xhr friendly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S2.define('select2/data/remoteQuery', [ | |
'./array', | |
'../utils', | |
'jquery' | |
], function (ArrayAdapter, Utils, $) { | |
function RemoteQueryAdapter($element, options) { | |
this.ajaxOptions = this._applyDefaults(options.get('remoteQuery')); | |
if (this.ajaxOptions.processResults != null) { | |
this.processResults = this.ajaxOptions.processResults; | |
} | |
RemoteQueryAdapter.__super__.constructor.call(this, $element, options); | |
} | |
Utils.Extend(RemoteQueryAdapter, ArrayAdapter); | |
RemoteQueryAdapter.prototype._applyDefaults = function (options) { | |
var defaults = { | |
data: function (params) { | |
return { | |
q: params.term | |
}; | |
}, | |
transport: options | |
}; | |
return $.extend({}, defaults, options, true); | |
}; | |
RemoteQueryAdapter.prototype.processResults = function (results) { | |
return results; | |
}; | |
RemoteQueryAdapter.prototype.query = function (params, callback) { | |
var matches = []; | |
var self = this; | |
this.ajaxOptions.transport({ | |
params: params, | |
callback: callback | |
}); | |
}; | |
return RemoteQueryAdapter; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment