即使在第二行,@key
以下内容也总是给出。0 1 2 3
请帮忙。
车把模板:
{{#grouped_each 4 orderData}}
<div class="row">
{{#each this }}
<div class="col-md-3">
<div class="thumbnail">
<img src="{{getImageSourceChannel ../../channelNames @key name}}" class="">
<div class="caption">
<p><b>{{getObjectAtIndex ../../channelNames @key}}</b></p>
<p class="">{{slices.4.count}} new orders</p>
<p class="">{{slices.3.count}} back orders</p>
</div>
</div>
</div>
{{/each}}
</div>
{{/grouped_each}}
车把部分:
Handlebars.registerHelper('grouped_each', function(every, context, options) {
var out = "", subcontext = [], i;
console.log(every);
console.log(context);
console.log(options);
if (context && context.length > 0) {
for (i = 0; i < context.length; i++) {
if (i > 0 && i % every === 0) {
out += options.fn(subcontext);
subcontext = [];
}
subcontext.push(context[i]);
}
out += options.fn(subcontext);
}
return out;
});