template7
template7 copied to clipboard
How to Assign The Select Element Value In a Loop
How do you achieve efficiently assigning the selected value to a dynamically loaded dropdown select element while looping in Template7?
I need too =/
Resolved!!
.js file
Template7.registerHelper('select', function (value, options) { var $el = $('<select />').html(options.fn(this)); $el.find('[value="' + value + '"]').attr({ 'selected': 'selected' }); return $el.html(); });
.html file
<select name="uf">
{{#select cliente.uf}}
<option value="0" selected>Selecione</option>
<option value="AC">Acre</option>
<option value="AL">Alagoas</option>
<option value="PB">Pernanbuco</option>
...
</select>