javascript - How to generate a Ractive <select> with only a max value -
using ractive, want generate dropdown number options 1 n.
a select element can generated using (source):
<select value='{{selectedcountry}}'> <option selected disabled>select country</option> {{#countries}} <option value='{{id}}'>{{name}}</option> {{/countries}} </select>
with:
ractive = new ractive({ el: mycontainer, template: mytemplate, data: { countries: [ { id: 'afg', name: 'afghanistan' }, { id: 'alb', name: 'albania' }, // , on... ] } });
so data change like:
ractive = new ractive({ el: mycontainer, template: mytemplate, data: { n: 50 } });
but syntax #countries
loop when have max value (n
)?
<select> {{#each array(n):i}} <option>option {{i}}</option> {{/each}} </select>
relevant docs:
- handlebars style sections
- adding array indexes
- use of
array(n)
calling array constructor function
Comments
Post a Comment