javascript - Decelerate Meteor page rendering for helper function -
i want count position of table children using jquery in meteor js helper function, empty result, because helper function returns before table data gets inserted.
here code:
<table class="table"> <thead> <tr> <th>#</th> <th>game</th> </tr> </thead> <tbody> {{#each games}} {{> game}} {{/each}} </tbody> </table> <template name="game"> <tr> <td>{{counter}}</td> <td>{{name}}</td> </tr> </template> template.game.helpers({ counter: function() { return $('table.table tbody tr td:contains("this.name")').index(); } });
it should like: 1 test 2 abc 3 helloworld ...
any appreciated.
the idea solution add array of games objects additional field called index
. later in game
template use {{index}}
.
below code should solve issue:
var games_with_index = games.find().map(function(document, index){ document.index = index; return document; }); <table class="table"> <thead> <tr> <th>#</th> <th>game</th> </tr> </thead> <tbody> {{#each games_with_index}} {{> game}} {{/each}} </tbody> </table> <template name="game"> <tr> <td>{{index}}</td> <td>{{name}}</td> </tr> </template>
see this: print loop index in meteor.js templates
Comments
Post a Comment