【问题标题】:how to set patch value (update the nested value ) in array in array in angular2?如何在angular2中的数组中设置补丁值(更新嵌套值)?
【发布时间】:2017-09-30 18:32:44
【问题描述】:

我有一个像

这样的嵌套数组
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 权限,当调用该函数时,权限相关的 ischecked 和 self ischecked 更改为 true,我完成的权限被检查为真正完美, 我正在努力做的是 ** self ** ischecked as true,

这是我的代码

 (<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

【问题讨论】:

  • '..' 是实际的错字还是有问题的错字?
  • 这是我项目中的一个场景

标签: angular angular2-routing angular2-forms angular2-directives


【解决方案1】:

试试这个

let x = (<FormArray>this.roleForm.controls['permission']).at(index).get('roles')
let y =   (<FormControl>x.controls[0])

y.patchValue({
        ischecked: true
      })

【讨论】:

    猜你喜欢
    • 2021-01-10
    • 2017-06-11
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2021-10-14
    • 2017-05-19
    • 2022-01-26
    • 1970-01-01
    相关资源
    最近更新 更多