A question on the {{for}} loop in jsRender.
The demo shows we can loop through a collection of complex objects and display their properties:
{{for languages}}
<div>
<em>{{>name}}</em>
</div>
{{/for}}
But what if my languages is only a List<string>? There will be no {{>name}} to be displayed. How can we reference the individual string values?
Thanks.
{{#data}}
Didn't work for me.
Something seems to have been changed, this is what did it for me:
{{>#data}}
You should be able to use #data to access the individual string values inside the loop.
You should use:
{{>#data}} or {{>}} - (encodes HTML)
{{:#data}} or {{:}} - (non HTML)
For example:
Let's say your languages object looks like this:
var languages = ['en', 'sp', 'zh'];
{{for languages}}
<div>
<em>{{>}}</em>
</div>
{{/for}}
Will result in:
<div>
<em>en</em>
</div>
<div>
<em>sp</em>
</div>
<div>
<em>zh</em>
</div>
Documentation
#data
Difference between : and >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With