我使用meteor 1.2.1和alanning:roles@1.2.14
尝试为帐户分配角色:
var users=[{username: "admin",email: 'admin@admin.com',verified: true,
password:"admin123",roles: 'admin'},
{username: "sheng",email: 'sheng@admin.com',verified: true,
password:"sheng123",roles: []},
{username: "test", email: "test@test.com",verified:true,
password: "test123",roles:[]}
];
_.each(users, function(user){
var id;
id=Accounts.createUser({
username:user.username,
email:user.email,
verified: true,
password:user.password,
profile:{name:user.username}
});
if(user.hasOwnProperty('roles') && user.roles.length>0){
Roles.addUsersToRoles(id, user.roles, Setting.name); ///error here
}
});
但如果我将上述代码更改为:
var users=[{username: "admin",email: 'admin@admin.com',verified: true,
password:"admin123",roles: 'admin'},
{username: "sheng",email: 'sheng@admin.com',verified: true,
password:"sheng123",roles: []},
{username: "test", email: "test@test.com",verified:true,
password: "test123",roles:[]}
];
_.each(users, function(user){
var id;
id=Accounts.createUser({
username:user.username,
email:user.email,
verified: true,
password:user.password,
profile:{name:user.username}
});
if(user.hasOwnProperty('roles') && user.roles.length>0){
console.log(user)
}
});
它有效,我不知道为什么我只是将角色分配给帐户并且上面出现错误以及如何将帐户分配给某个角色。