我有一个嵌套数组,例如
permission": [
{
"id": 2,
"key": "creatBusinessPermission",
"legend": "BusinessModule",
"ischecked": false,
"label": " Create Business Settings",
"roles": [
{
"id": 1,
"key": "self",
"ischecked": false
},
{
"id": 2,
"key": "selfrole",
"ischecked": false
},
{
"id": 3,
"key": "other",
"ischecked": false
},
{
"id": 4,
"key": "All",
"ischecked": false
}
]
},
{
"id": 3,
"key": "editBusinessPermission",
"legend": "BusinessModule",
"ischecked": true,
"label": " Edit Business Settings",
"roles": [
{
"id": 1,
"key": "self",
"ischecked": false
},
{
"id": 2,
"key": "selfrole",
"ischecked": false
},
{
"id": 3,
"key": "other",
"ischecked": false
},
{
"id": 4,
"key": "All",
"ischecked": false
}
]
}]
对于上面的数组,我使用响应式(Reactive)形式, 构建表单后,我有一个关于 onchange 权限的函数,当调用该函数时,会检查与权限相关的内容,并且 self 会检查更改为 true,我完成的权限检查为 true 完美, 我正在努力使** self **被检查为真实,
这是我的代码
(<FormArray>this.roleForm.controls['permission']).at(index).patchValue({
ischecked : true
}) This is works fine
在这里我不知道该怎么做
(<FormArray>this.roleForm.controls['permission']).at(index).get('roles').at(1)..patchValue({
ischecked : true
}) this code giving error, Probebly I did n't no how to do
最佳答案
试试这个
let x = (<FormArray>this.roleForm.controls['permission']).at(index).get('roles')
let y = (<FormControl>x.controls[0])
y.patchValue({
ischecked: true
})
关于angular - 如何在 angular2 的数组中的数组中设置补丁值(更新嵌套值)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43751364/