0
在我的Meteor應用程序中,這個帶有方法調用的投票功能工作正常,直到我包含一個輸出lodash的compability腳本爲var _ = runInContext();
現在我得到的錯誤是_.contains
不是函數。不用lodash調用方法的另一種方法是什麼?
是否有另一種方式來運行此功能,並呼籲沒有_.contains
?
在按鈕點擊:
"click [data-action='addLikes']": function (event) {
event.preventDefault();
var song = Songs.findOne({_id: this._id});
upvote(song);
}
服務器方法:
upvote = function(currentSong){
var user = Meteor.user();
if(!user){
return false;
}
if (currentSong) {
if (_.contains(currentSong.voters, Meteor.userId())) {
return false;
}
Songs.update(currentSong._id, {$addToSet: {voters: Meteor.userId()}, $inc: {likes: 1}});
}
};
哦,更容易比我想象。按照描述工作,謝謝! –