我有一个模板:
<template name="week_list">
{{#each days}}
{{day_of_month this}} <br />
{{#each action_log_on_day this}}
{{Name}} : {{Score}} <br />
{{/each}}
{{/each}}
</template>
有没有办法对模板中的所有“分数”求和,或者我需要为它创建一个单独的 js 函数(带有自己的 mongo 查询)?
最佳答案
您需要为此创建一个单独的函数,因为 meteor 中模板的唯一目的是显示内容,您根本无法在模板中实现任何逻辑。您的函数可能与此类似:
var sum = 0;
Documents.find({...}).forEach(function (doc) { sum += doc.Score; });
return sum;
关于javascript - 模板中的数字总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16130632/