【发布时间】:2016-06-20 21:15:07
【问题描述】:
我正在尝试通过将 usersId 保存到已登录的用户帐户来创建收藏按钮。这个概念是,如果有一个 userId(用户是最喜欢的),否则用户不是最喜欢的。问题是我收到一个错误update failed: Error: Favorites must be an array,我不确定这意味着什么。
路径:schema.js
Schema.UserProfile = new SimpleSchema({
"favorites.$.favorite": {
type: Object
}
});
路径:studentlist.js
Template.student.events({
'click .favourite':function(event,template) {
console.log('click');
var candidateId = this._id;
Meteor.users.update({_id: Meteor.userId() }, { $set: { "profile.favorites": candidateId }});
}
});
【问题讨论】:
-
请参阅"Should questions include “tags” in their titles?",其中的共识是“不,他们不应该”!
-
没问题,安德烈亚斯,我会接受的。仍在学习正确的做事方式。
-
您是否使用
aldeed:collection2将架构附加到集合中?当您指定它应该是一个带有favorites.$的数组时,为什么要尝试将favorites设置为一个ID,它通常是一个字符串?请edit您的问题提供minimal reproducible example。
标签: meteor simple-schema