Skip to content

Instantly share code, notes, and snippets.

@hvitorino
Created October 18, 2011 10:23
Show Gist options
  • Save hvitorino/1295108 to your computer and use it in GitHub Desktop.
Save hvitorino/1295108 to your computer and use it in GitHub Desktop.
jquery plugin
(function ($) {
$.fn.carregaOptions = function(configs) {
var defaults = {
options : [],
template: function(val) {
return '<option value="{0}">{1}</option>'.format(val[0], val[1]);
}
};
return this.each(function(val) {
if (configs) {
$.extend(defaults, configs);
}
var $this = $(this);
$this.html('');
$(defaults.options).each(function () {
var item = defaults.template.call(this, arguments);
$this.append(item);
});
});
};
})(jQuery);
(function($) {
$.fn.carregaSelect = function(selects) {
return this.each(function() {
for (var selectId in selects) {
$('#' + selectId, this).carregaOptions({
options: selects[selectId.toString()]
});
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment