Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

In Meteor is it possible to flush per row of a table?

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
:
(variable number of rows)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...