我有一个像
这样的嵌套数组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
}
]
}]
对于上面的数组我正在使用反应形式, 构建一个表单后,我有一个函数用于onchange的权限,当调用该函数的权限相关缺血和自我缺血改变为真时,我完成了pesrmission被检查为真正的完美, 我正在努力使**自我**缺血为真,
这是我的代码
(<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
答案 0 :(得分:2)
试试这个
let x = (<FormArray>this.roleForm.controls['permission']).at(index).get('roles')
let y = (<FormControl>x.controls[0])
y.patchValue({
ischecked: true
})