0
我有一个页面,我显示一个列表用户。我希望当前用户“is_teacher”能够“喜欢”列表中的个人用户。这些喜欢只有老师才能看到。我认为最好的方法是在集合中添加一个likes: String
并存储students_Id,但我的代码必须离开,因为它不起作用。有人可以结帐我做了什么我让我知道我要去哪里错了。流星 - 添加喜欢/喜欢的用户帐户
路径:Schemas.js
Schema.UserProfile = new SimpleSchema({
likes: {
type: [String],
optional: true
}
});
路径:sudentList.html
<template name="studentList">
{{#each student}}
{{#if like}}
<button class="like">Unlike</button>
{{else}}
<button class="like">Like</button>
{{/if}}
{{/each}}
</template>
路径: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}});
}
});