小编Shy*_*shi的帖子

如何使用多层嵌套 json 值修补反应式表单

我正在使用包含 formArray、formGroups 和 formControls 的多重嵌套(无限级)反应表单的值。哪个存储在数据库中。

目前,我正在使用递归函数修补表单,该函数循环遍历整个 JSON,并根据键和值创建 formArrays、formGroups 和 formControls。

现在的问题是,我使用的这种方法从性能角度来看并不好,那么有没有更好的方法来一次性修补这种多重嵌套形式呢?(只需创建表单,无需以 HTML 形式显示)

这是供问题参考的简化 JSON -

任何部分都可以有子部分,然后子部分可以有某种类型的部分

const formDataSections = [
  {
    index: 1,
    sectionName: "",
    subSections: [
      {
        index: 1,
        subSectionName: "",
        sections: [
          {
            index: null,
            sectionName: "",
            subSections: [
              {
                index: null,
                subSectionName: "",
                sections: [
                  {
                    index: null,
                    sectionName: "",
                  },
                  {
                    index: null,
                    sectionName: "",
                    subSections: [
                      {
                        index: null,
                        subSectionName: "",
                        sections: [
                          {
                            index: null,
                            sectionName: "",
                          },
                          {
                            index: null,
                            sectionName: "", …
Run Code Online (Sandbox Code Playgroud)

javascript angular angular-reactive-forms

7
推荐指数
1
解决办法
422
查看次数