在 Meteor 中是否可以刷新表的每一行? [英] In Meteor is it possible to flush per row of a table?

查看:35
本文介绍了在 Meteor 中是否可以刷新表的每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Meteor 应用程序,我必须在其中显示计算结果的可变长度表.计算在 Meteor 中完成并显示在行的单元格中 - 表中的每个单元格都是基于复杂计算的数字结果.最后我想显示每一行的总计算.

I am building a Meteor app where I have to display a variable length table of calculation results. The calculations are done in Meteor and displayed in cells of the rows - each cell in the table is a numeric result based on a complex calculation. Finally I want to display a total calculation for each row.

calcresult1 calcresult2 row1sum
calcresult3 calcresult4 row2sum
:
(可变行数)

calcresult1 calcresult2 row1sum
calcresult3 calcresult4 row2sum
:
(variable number of rows)

如何根据每行的 calcresults 有效地计算行总和?

How can I efficiently calculate the row sums reactively from the calcresults on each row?

我可以设置单个会话变量,在渲染行中的单元格时对其求和,然后在渲染每个行时刷新总数吗?

Can I setup a single session variable, sum to it when rendering the cells in the row, and then flush the total as each rowsum is to be rendered?

推荐答案

如果行每次都有相同数量的单元格,您可以将每个单元格助手的结果传递给最终助手.

If the rows have the same number of cells each time, you could pass the results from each cell helper to a final helper.

<template name="calcTable">
    <table>
        {{#each calcRow}}
            <tr>
                <td>{{calcresult1}}</td>
                <td>{{calcresult2}}</td>
                <td>{{rowsum calcresult1 calcresult2}}</td>
            </tr>
        {{/each}}
    </table>
</template name="calcTable">

-

Template.calcTable.helpers({
    calcresult1: function() {
        return result;
    },

    calcresult2: function() {
        return result;
    },

    rowsum: function(calcresult1, calcresult2) {
        return calcresult1 + calcresult2;
    }
});

这篇关于在 Meteor 中是否可以刷新表的每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆