Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For loop in jquery template?

Does anyone know if it is possible to put a for loop into a jquery template?

For example if I have something like ${userCap} where the value of userCap is 10, how could I add a for loop to the template to add options to a select while i is less than userCap?

<select>
{{for(i=1; i<=userCap; i++)}}
<option value="${i}">${i}</option>
{{/for }}
</select>

As per Bergi's request - the plugin I am using is... jQuery Templates https://github.com/BorisMoore/jquery-tmpl

like image 221
Jose the hose Avatar asked Oct 14 '25 23:10

Jose the hose


1 Answers

The documentation suggests it cannot.

However you can use each:

<select>
{{each(i) values}}
    <option value="${i}">${i}</option>
{{/each}}
</select>

See this fiddle

like image 128
Rik Avatar answered Oct 17 '25 12:10

Rik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!