Meteor - Adding a favourite/like user accounts -
i have page display list users. current user "is_teacher" able 'like' individual users in list. likes visible teacher. thought best way add likes: string
in collection , store students_id code must way off because not working. can checkout i've done let me know i'm going wrong.
path: schemas.js
schema.userprofile = new simpleschema({ likes: { type: [string], optional: true } });
path: sudentlist.html
<template name="studentlist"> {{#each student}} {{#if like}} <button class="like">unlike</button> {{else}} <button class="like">like</button> {{/if}} {{/each}} </template>
path: studentlist.js
template.studentlist.helpers({ like: function() { return meteor.users.findone({likes: this._id}); } }); template.studentlist.events({ 'click #like':function(event,template) { var student = this._id; meteor.users.update({likes: student}, {$set:{likes:!student}}); } });
posting answer because can't comment.
it's unclear what's going on because code bit of mess, , need bit more information "it's not working" diagnose issue.
some obvious points are:
- your button has class (
.
), event bound id (#
) - your update function odd. (to least!)
likes
array, wouldn't use$set
stringstudent
string,!student
false
- presumably since schema user profiles, find/update operations should go
profile.likes
notlikes
this guess, think event should more like:
template.studentlist.events({ 'click #like':function(event,template) { var student = this._id; var teacher = meteor.userid(); meteor.users.update({_id: student}, {$push:{"profile.likes": teacher}}); } });
but it's hard because i'm not 100% sure you're trying do.
Comments
Post a Comment