@orpha
To use values in a Mustache loop at jQuery, you can follow these steps:
1 2 3 4 5 6 7 |
<script id="template" type="x-tmpl-mustache"> <ul> {{#items}} <li>{{name}}</li> {{/items}} </ul> </script> |
1 2 3 4 5 6 7 |
var data = { items: [ {name: 'Item 1'}, {name: 'Item 2'}, {name: 'Item 3'} ] }; |
1 2 3 |
var template = $('#template').html(); var rendered = Mustache.render(template, data); $('#output').html(rendered); |
In this example, the JavaScript object data
contains an array of items with a name
property. The Mustache template loop iterates over each item in the items
array and displays the name
property of each item in a list. The rendered HTML is then inserted into an element with the id output
.
By following these steps, you can easily use values in a Mustache loop at jQuery.