{
"data": {
"id": 3,
"name": "random",
"email": "[email protected]",
"created_at": "2017-02-06 18:16:06",
"updated_at": "2017-02-06 18:16:06",
"roles": [
{
"id": 1,
"name": "ADMIN",
"access": {
"role4": true,
"role3": true,
"role2": true,
"role1": true
},
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00"
}
]
}
}
我试图访问“访问”,并收到成效真/假,但它不工作Javascrypt(VueJS)对象与数组
currentUser.roles[0].access['role1'];
错误:无法读取属性“0”的未定义
但
console.log(currentUser.roles[0].access['role1']); // returns true
和
currentUser.roles // gives me all the roles
数据通过Laravel Transformer传递到前端。
注意:使用VueJs,这里面的方法:
是不是data.roles [0]。访问[ 'role1上']? – choasia
不,它是undefined –
我的意思是... currentUser从哪里来?我找不到它在你的对象 – choasia