我正在使用Loopback Framework,做一个web项目.但我认为我在这里暴露的问题与此关系不大,但具有一般的Javascript/Node.JS知识.
在代码的一部分,我正在做:
roleMapping.find({
where: {
principalType: 'USER',
principalId: context.principals[0].id
},
include: 'role'
}, function(err, roles){
console.log(roles[0]);
for (var i in roles)
{
if (roles[i].role.name === 'teamLeader' &&
roles[i].groupId === context.modelId)
{
cb(null,true);
}else {
cb(null,false);
}
}
});
Run Code Online (Sandbox Code Playgroud)
好的,但是在尝试比较时失败了roles[i].role.name.所以,我记录了roles[i]对象包含的内容.
{ groupId: 1,
id: 3,
principalType: 'USER',
principalId: 1,
roleId: 2,
role:
{ id: 2,
name: 'teamLeader',
description: 'The leader(s) of a team',
created: null,
modified: null } }
Run Code Online (Sandbox Code Playgroud)
好吧,没有错,但它仍然失败,所以我试图打印role属性.令我惊讶的是:
{ [Function]
update: [Function], …Run Code Online (Sandbox Code Playgroud)