0
我试图访问集合名称的帖子来检查当前用户是否已经喜欢。如果喜欢,然后显示不同颜色的喜欢的按钮。 问题是该函数被称为两次。在使用流星调用时多次访问流星中的函数
isLiked: function() {
let self = this;
console.log();
Meteor.call('posts.isLiked', self._id, (error, result) => {
console.log(result);
return result;
});
}
上述函数调用posts.isLiked如下 -
'posts.isLiked': (_id) => {
check(_id, String);
if (!Meteor.user()) {
throw new Meteor.Error(401, 'You need to be signed in to continue');
}
if (!_id) {
throw new Meteor.Error(422, '_id should not be blank');
}
return (Posts.find({ _id: _id , already_voted: { "$in" : [Meteor.userId()]} }).count() == 1);
}
控制台显示输出的2倍。 任何帮助,将不胜感激。
isLiked被称为两次,因此流星调用也被称为两次。 –
那么,现在我们该如何帮忙?我们没有你的代码,你在做什么?为什么叫两次? –
在Html部分,我使用{{#if isLiked}} –