Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度6-更新阵列内的深度对象_Angular_Typescript - Fatal编程技术网

Angular 角度6-更新阵列内的深度对象

Angular 角度6-更新阵列内的深度对象,angular,typescript,Angular,Typescript,我有一个配置对象要从X组件发送到Y组件 从Y组件中,我过滤列以仅获得唯一的monoselect,然后针对每个列,我要更新monoselectConfig的选项 问题是我可以更新选项,但是当我显示配置对象时,我找不到我刚才所做的修改 您正确地进行了筛选,但没有正确地更新对象 我已经在stackblitz中查看了您的代码,您只需要对ngOnChanges()方法稍作修改 因此,只需使用下面的代码更新ngOnChanges()方法。这将更新您的配置对象 ngOnChanges(changes: Si

我有一个配置对象要从X组件发送到Y组件

从Y组件中,我过滤列以仅获得唯一的monoselect,然后针对每个列,我要更新monoselectConfig的选项

问题是我可以更新选项,但是当我显示配置对象时,我找不到我刚才所做的修改


您正确地进行了筛选,但没有正确地更新对象

我已经在stackblitz中查看了您的代码,您只需要对ngOnChanges()方法稍作修改

因此,只需使用下面的代码更新ngOnChanges()方法。这将更新您的配置对象

ngOnChanges(changes: SimpleChanges) {
    if (changes["config"] && changes["config"].currentValue) {

      this.configuration = changes["config"].currentValue;

      // get all unique monoselect
      let monoselectsUnique = this.configuration.columns.filter(element => element.type === "monoselect" && element.unique == true);
      console.log(monoselectsUnique)
      if (monoselectsUnique.length > 0) {
        monoselectsUnique.forEach(element => {

          // get all options not exist in the array result
          let newOption = element.monoselectConfig.options.filter(item => !this.config.value.map(item => item[element.field].code).includes(item.code));

          // update the config object with the new option
          // monoselectsUnique = { ...monoselectsUnique.monoselectConfig, options: newOption }
          element.monoselectConfig.options= newOption
        })
         console.log(monoselectsUnique)
        console.log(this.configuration)
      }

    }
  }

我希望下面的答案解决了您的问题,如果是这样,请也投票,以便对其他人也有用。
ngOnChanges(changes: SimpleChanges) {
    if (changes["config"] && changes["config"].currentValue) {

      this.configuration = changes["config"].currentValue;

      // get all unique monoselect
      let monoselectsUnique = this.configuration.columns.filter(element => element.type === "monoselect" && element.unique == true);
      console.log(monoselectsUnique)
      if (monoselectsUnique.length > 0) {
        monoselectsUnique.forEach(element => {

          // get all options not exist in the array result
          let newOption = element.monoselectConfig.options.filter(item => !this.config.value.map(item => item[element.field].code).includes(item.code));

          // update the config object with the new option
          // monoselectsUnique = { ...monoselectsUnique.monoselectConfig, options: newOption }
          element.monoselectConfig.options= newOption
        })
         console.log(monoselectsUnique)
        console.log(this.configuration)
      }

    }
  }