Meteor模板每次循环,提供其他模板每次X结果
Meteor template each loop, provide other template each X results
meteor 解析带有{{#each}}模板逻辑的集合时是否可以插入特定的数据,只有每个X集合条目?
示例:
HTML
{{#each collection}}
<div>
<p>{{collectionparam1}} - {{collectionparam2}}</p>
{{#if **collection[only multiple of 2]**}}
<p>I show this {{collectionparam3}} only each 2 entries</p>
{{/if}}
</div>
{{/each}}
结果:
Billy - 24
Joe - 12
I show this banana only each 2 entries
Bob - 88
Maria - 5
I show this cherry only each 2 entries
Samantha - 102
Henry - 43
I show this apple only each 2 entries
如果可能的话,我必须在{{#if}}逻辑上添加什么?
感谢您的帮助。
这类似于this question。试一试:
html
{{#each collection}}
<div>
<p>{{collectionparam1}} - {{collectionparam2}}</p>
{{#if shouldShow @index}}
<p>I show this {{collectionparam3}} only each 2 entries</p>
{{/if}}
</div>
{{/each}}
js
Template.myTemplate.helpers({
shouldShow: function (index) {
return (index + 1) % 2 === 0;
}
});
meteor 解析带有{{#each}}模板逻辑的集合时是否可以插入特定的数据,只有每个X集合条目?
示例:
HTML
{{#each collection}}
<div>
<p>{{collectionparam1}} - {{collectionparam2}}</p>
{{#if **collection[only multiple of 2]**}}
<p>I show this {{collectionparam3}} only each 2 entries</p>
{{/if}}
</div>
{{/each}}
结果:
Billy - 24
Joe - 12
I show this banana only each 2 entries
Bob - 88
Maria - 5
I show this cherry only each 2 entries
Samantha - 102
Henry - 43
I show this apple only each 2 entries
如果可能的话,我必须在{{#if}}逻辑上添加什么?
感谢您的帮助。
这类似于this question。试一试:
html
{{#each collection}}
<div>
<p>{{collectionparam1}} - {{collectionparam2}}</p>
{{#if shouldShow @index}}
<p>I show this {{collectionparam3}} only each 2 entries</p>
{{/if}}
</div>
{{/each}}
js
Template.myTemplate.helpers({
shouldShow: function (index) {
return (index + 1) % 2 === 0;
}
});