【发布时间】:2014-08-09 05:46:35
【问题描述】:
我正在尝试制作个人资料页面,我需要在模板中显示个人资料名称和简历。问题是我无法获取每个配置文件对象的 ID。如果我可以像在book 中使用 postId 一样获取每个配置文件的 ID。 Here 下面的代码是我认为它可以工作但没有的方式。如果您告诉我如何获得 ID,那将非常感谢。
Profile = new Meteor.Collection('profile');
Profile.allow({
update: ownsDocument
})
Profile.deny({
update: function(profileId, profile, fieldNames) {
return (_.without(fieldNames, 'bio').length > 0);
}
});
Accounts.onCreateUser(function(options, user){
Meteor.methods({
profile: function(postAttributes) {
var user = Meteor.user();
var profile = _.extend(_.pick(options.profile, 'bio'), {
userId: user._id,
profilename: user.username,
submitted: new Date().getTime(),
postsCount: 0, posts : []
});
var profileId = Profile.insert(profile);
return profileId;
}
});
return user;
});
【问题讨论】:
-
您可以在您的源代码示例中添加一些缩进吗?没有它就很难读。另外,为什么要在
onCreateUser回调中定义post方法?我认为应该在全球范围内进行。 -
好的,谢谢,我会尝试并立即修复我的代码中配置文件的错字,我一定是输入错误了
-
创建新帐户时,我需要为每个用户创建个人资料。
-
明白,但这不是
Meteor.methods的目的。 -
好吧,这只是我尝试过的其中一种方法,大多数没有包括 Meteor.methods 任何帮助都很好,我对流星很陌生。从理论上讲,您将如何创建它。谢谢
标签: javascript meteor user-profile