javascript - Update Meteor Leaderboard with own data -


i've changed meteor example leaderboard voting app. have documents array , in array there 6 values. sum of 6 values works fine, not updating , showing values in app.

the values updating, if click on them. problem is, booknames (it's voting app books) "selected_books" variable (previously selected_players), don't know how can book names.

by way: _id book names. give code snippets , hope, have solution.

this document database:

{     _id: "a dance dragons: part 1",     isbn: 9780007466061,     flag: 20130901,     score20130714: [1,2,3,4,5,0], } 

parts of html file:

<template name="voting">     ...     <div class="span5">         {{#each books}}             {{> book}}         {{/each}}     </div>     ... </template>   <template name="book">     <div class="book {{selected}}">         <span class="name">{{_id}}</span>         <span class="totalscore">{{totalscore}}</span>     </div> </template> 

and parts of javascript file:

template.voting.books = function () {     var total = 0;     var book = session.get("selected_book");      books.find({_id:book}).map(function(doc) {         (i=0; i<6; i++) {             total += parseint(doc.score20130714[i], 10);         }     });     books.update({_id:book}, {$set: {totalscore: total}});      return books.find({flag: 20130901}, {sort: {totalscore: -1, _id: 1}}); }; 

thanks in advance

don't update data in helper fetch it! use second helper aggregating information or transform modifying data items. example:

template.voting.books = function() {     return books.find({}, {sort: {totalscore: -1, _id: 1}}); };  template.books.totalscore = function() {     var total = 0;     for(var i=0; i<6; i++) {         total += this.score[i];     }     return total; }; 

as side note, do not use construct for (i=0; i<6; i++), it's deadly. always declare index variables: for (var i=0; i<6; i++).


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -