简体   繁体   English

将自定义用户字段添加到Meteor.js

[英]Add custom user fields to Meteor.js

I am new to programming and Meteor.js. 我是编程和Meteor.js的新手。 I am trying to build a question app where an admin can post questions, then after awhile be able to mark them as true or false. 我正在尝试构建一个问题应用程序,管理员可以在其中发布问题,然后可以将其标记为是或否。 When user clicks on "Yes" or "No" the app adds their user id to either usersTrue or usersTrue arrays. 当用户单击“是”或“否”时,应用程序会将其用户ID添加到usersTrueusersTrue数组中。 Also the question _id is added to the users profile so it can check if the user has already answered the question. _id问题_id添加到用户个人资料中,以便可以检查用户是否已经回答了问题。 Finally, when the admin clicks true or false it loops through the list of users who answered correctly and increases their rightCount by 1 or if they answered incorrect increases their wrongCount by 1. 最后,当管理员单击“是”或“ rightCount ,它将循环显示正确回答的用户列表,并将rightCount增加1,如果回答不正确,则将错误wrongCount增加1。

I have figured out how to insert the user's id into the right question array. 我想出了如何将用户ID插入正确的问题数组。

My question is how can I add custom fields to the user when their account is created, so I can check if the user has answered the question already. 我的问题是创建帐户后如何向用户添加自定义字段,以便检查用户是否已经回答了该问题。

I have tried creating /server/user.js with onCreateUser 我试图用onCreateUser创建/server/user.js

Accounts.onCreateUser(function(options, user){
profile = _.insert({
    questionsAnswered: [],
    rightCount: 0,
    wrongCount: 0
});

user.profile = profile

return user;

If I am doing this completely wrong or there is a more efficient way of doing this whole process, I would be interested in hearing it. 如果我做的完全错误,或者有更有效的方法来完成整个过程,那么我很想听听它。

I had a similar problem. 我有一个类似的问题。 You can try this: 您可以尝试以下方法:

Accounts.onCreateUser(function(options, user){
  profile = {
      questionsAnswered: [],
      rightCount: 0,
      wrongCount: 0
  };

  user.profile = profile

  return user;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM