Updating A Sub-document Through Meteor Methods Via A Click Function Proving Problematic
I have a button .toggle-addToSet that captures two integers, this.id which is the current posts' id, and setid (sid) which is an _id of a collection Set which the user has the abi
Solution 1:
You have an extra parameter in your addingSets
method.
Currently you have addingSets: function(set, sid, ob)
defined in the function.
When you're calling it from the client, you're doing it like so:
Meteor.call('addingSets', ob, sid, function(error, user) {...}
Notice that the function is expecting 3 parameters to be passed to it while you're giving it only 2. So in your case, ob
gets mapped to set
, and sid
gets mapped to sid
and since the 3rd param isn't being passed, it's undefined.
Helper:
Template.latestSingle.events({
'click .toggle-addToSet': function(e, template) {
var ob = this.id
console.log(ob);
var sid = $(e.currentTarget).data('setid');
Meteor.call('addingSets', ob, sid, function(error, user) {
console.log(ob)
});
}
});
Server:
Meteor.methods({
addingSets: function(ob, sid) {
console.log(sid);
console.log(ob);
Sets.update({
_id: sid
},
{
$addToSet: {
ArticleId: ob
}
});
}
});
The positions and the params passed are important.
Post a Comment for "Updating A Sub-document Through Meteor Methods Via A Click Function Proving Problematic"