Calculating collection data before rendering in Meteor.js -
i'm new meteor.js , want understand basics. want calculations data in collection , render dom. should rendered dom {{#each}} loop. how can this?
the html looks similar this:
{{#each location}} <div>{{name}}</div> <div>{{calculated_distance}}</div> {{/each}}
the js:
template.list.location = function (){ return collection.find({ location : { $near : { $geometry : { type : "point", coordinates : [long, lat] }, $maxdistance: 430 }}}); }
this allows me post data in collection. how access {{calculated_distance}} each document in collection?
if understand correctly can use helper:
template.list.helpers ({ calculated_distance: function() { var lat = this.location.coordinates.lat; var lng = this.location.coordinates.long; var somecalculation = ... return somecalculation; } });
inside helper have context of this
specific element in location
collection (as loop through them). in helper can calculate distances need , show them in html. stands right now, html fine.
Comments
Post a Comment