Get the first 3 elements of the main collection in an underscore pattern
{{_.each(model, function(item) { }}
<h5 style="color:#F30;">{{=item.name}}</h5>
{{for (i = 0; i < item.subcollection.length; i++) { }}
<li><a>{{=item.subcollection[i].split('#')[0]}}</a></li>
{{ } }}
{{ });}}
I have an underscore pattern for rendering a collection of base models that contains a subcollection inside. But I only need to display the first 3 collections when rendering. ny help
+3
source to share
1 answer
I'm not sure what you are trying to do, but if you only want the first three to be done, set the counter to 3 instead of collection.length
{{for(j=0;j<3;j++){ }}
<h5 style="color:#F30;">{{=model[j].name}}</h5>
{{for (i = 0; i < model[j].subcollection.length; i++) { }}
<li><a>{{=model[j].subcollection[i].split('#')[0]}}</a></li>
{{ } }}
{{ } }}
Note: Make sure the length is at least 3.
+1
source to share