Filip Blaauw Filip Blaauw - 1 year ago 84
Javascript Question

Another way to call method without lodash?

In my Meteor app, this voting function with a method call was working fine, until I included a compability script that exports lodash as

var _ = runInContext();
Now I get error that
is not a function.

Is there another way to run this function and call without

On button click:

"click [data-action='addLikes']": function (event) {
var song = Songs.findOne({_id: this._id});

Server method:

upvote = function(currentSong){
var user = Meteor.user();
return false;
if (currentSong) {
if (_.contains(currentSong.voters, Meteor.userId())) {
return false;
Songs.update(currentSong._id, {$addToSet: {voters: Meteor.userId()}, $inc: {likes: 1}});

Answer Source

If currentSong.voters is just an array, you can go with two solutions:




currentSong.voters.indexOf(Meteor.userId()) > -1

or a shorthand

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download