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}});
}
});