templates - how to access an object from meteor.call -



templates - how to access an object from meteor.call -

just trying figure things out in meteor js. stuck trying meteor.call result object passed template. here code:

html template <template name="showtotals"> <div class="container"> {{#each recordcnt}} {{/each}} </div> </template> client js //get count per item template.showtotals.recordcnt = function(){ meteor.call('getcounts', function(err, result) { if (result) { //console.log(result); <-this shows object in javascript console homecoming result; } else { console.log("blaaaa"); } }); } server js meteor.startup(function () { meteor.methods({ getcounts: function() { var pipeline = [{$group: {_id: null, count: {$sum : 1}}}]; count_results = mycollection.aggregate(pipeline); homecoming count_results; } }); }); global js mycollection = new meteor.collection('folks');

i have tried adding console.log(result) results of call, , displays in javascript console expected results. cannot populate recordcnt however.

any ideas?

you can't way want because callback meteor.call runs asynchronously.

you can, however, utilize callback set session value , have helper read session.get() instead.

template.showtotals.rcdcount = function() { homecoming session.get('rcdcount'); } template.showtotals.rendered = function() { meteor.call('getcounts', function(err, result) { if (result) { session.set('rcdcount', result); } else { console.log("blaaaa"); } }); }

see here similar reply includes illustration of "hacky" way of doing it.

templates object meteor callback server

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -