javascript - In Meteor.js, Why is this.userId == undefined? -
i'm learning meteor following book, , right want insert()
userid
of user logged in.
template.categories.events({ 'keyup #add-category': function(e, t) { if(e.which == 13) { var catval = string(e.target.value || ""); if(catval) { lists.insert({category: catval, owner: this.userid}); console.log(this.userid); session.set('adding_category',false); } } },
however this.userid
undefined, insert()
didnt work expected. what's missing working?
somehow works in code below (userid
defined):
lists.allow({ insert: function(userid, doc) { return adminuser(userid); }, update: function(userid, docs, fields, modifier) { return adminuser(userid); }, remove: function(userid, docs) { return adminuser(userid); } });
update
why on server-side, this.userid
works not meteor.userid()
?
meteor.publish("categories", function() { return lists.find({owner:this.userid}, {fields:{category:1}}); });
you should use meteor.userid()
instead.
Comments
Post a Comment