Created
October 18, 2011 10:23
-
-
Save hvitorino/1295108 to your computer and use it in GitHub Desktop.
jquery plugin
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
(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