javascript - Passing array via ReactiveVar in Meteor -


i have meteor method returns user accounts on application

returnusers: function(){     return meteor.users.find().fetch(); } 

i'm using new reactivevar pass return value of meteor method template helper:

template.listviewtemplate.created = function (){     var self = this;     self.myasyncvalue = new reactivevar("waiting response serv er...");     meteor.call('returnusers', function (err, users) {         if (err)             console.log(err);         else              self.myasyncvalue.set(users);     }); }  template.listviewtemplate.helpers({     usercollection: function(){         return template.instance().myasyncvalue.get();     } }); 

but when go render users view, console error reads

{{#each}} accepts arrays

when render without #each iterator, using

<ul id='userslist'>     {{usercollection}} </ul> 

the output on web-page accurately reflects number of users (2), reads

[object object],[object object]

i'm pretty sure there funkiness going on here because i'm using global meteor collection (meteor.users.find().fetch(), opposed having defined own collection), i'm not sure how around it.

i want display list of users current user can click user , share document them--not sure how around this.

you don't need use reactive variable this. function @ template.listviewtemplate.created not container in autorun, means: won't recomputed.

the best approach scenario is: use variable status ( loading, loaded, error) , variable save array attach self. reactivity cool should use when needed.

about:

[object object],[object object]

this happening because you're not extracting value form object provided nor looping using {{#each}}.

your solutions listing users dangerous , inefficient. you're sending client fields user collection, including login tokens.

the best approach create subscription send necessaries fields like: _id, info.firstname. should have criteria list users , use pagination. consider search feature such purpose.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -