Skip to content

Instantly share code, notes, and snippets.

@AbraaoAlves
Forked from hvitorino/jqueryplugin
Created October 18, 2011 13:36
Show Gist options
  • Save AbraaoAlves/1295439 to your computer and use it in GitHub Desktop.
Save AbraaoAlves/1295439 to your computer and use it in GitHub Desktop.
jquery plugin carregaSelects
(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 select = $("<select>"); //objeto para aglomerar os options em memoria
$(defaults.options).each(function () {
var item = defaults.template.call(this, arguments);
select.append(item);
});
$(this).html(select.html()); //javascript performance
});
};
//use like this:
//$.carregaSelects({
// "seletor" : "valor/*[options]*/",
// "#idSelector": "valor2/*[options]*/"
//});
$.carregaSelects = function(selects) {
for (var seletor in selects) {
$(selector).carregaOptions(selelcts[selector]/*[options]*/);
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment