0

要求是,在一个新的组件对话框中,我需要标签包含两个通用 CTA 配置,例如: 在此处输入图像描述

目前,我的新组件对话框设置如下:

<tab3
          jcr:description="Primary CTA items"
          jcr:primaryType="nt:unstructured"
          jcr:title="Primary CTA"
          granite:class="tab-wrapper"
          sling:resourceType="granite/ui/components/coral/foundation/container">
        <items jcr:primaryType="nt:unstructured">
          <columns
              jcr:primaryType="nt:unstructured"
              sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
              margin="{Boolean}true">
            <items jcr:primaryType="nt:unstructured">
              <column
                  jcr:primaryType="nt:unstructured"
                  sling:resourceType="granite/ui/components/coral/foundation/container">
                <items jcr:primaryType="nt:unstructured">
                  <cta
                      jcr:primaryType="nt:unstructured"
                      sling:resourceType="granite/ui/components/coral/foundation/include"
                      path="myproject/folder/components/commons/cta/content/items/columns/items/column"/>
                </items>
              </column>
            </items>
          </columns>
        </items>
      </tab3>
      <tab4
          jcr:description="Secondary CTA items"
          jcr:primaryType="nt:unstructured"
          jcr:title="Secondary CTA"
          granite:class="tab-wrapper"
          sling:resourceType="granite/ui/components/coral/foundation/container">
        <items jcr:primaryType="nt:unstructured">
          <columns
              jcr:primaryType="nt:unstructured"
              sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
              margin="{Boolean}true">
            <items jcr:primaryType="nt:unstructured">
              <column
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/coral/foundation/container">
                <items jcr:primaryType="nt:unstructured">
                  <cta2
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="granite/ui/components/coral/foundation/include"
                    name="./cta2/"
                    path="myproject/folder/components/commons/cta/content/items/columns/items/column"/>
                </items>
              </column>
            </items>
          </columns>
        </items>
      </tab4>

如您所见,我正在使用sling:resourceType="granite/ui/components/coral/foundation/container"

指向通用 cta 对话框配置path="myproject/folder/components/commons/cta/content/items/columns/items/column"

问题是,在我构建它之后,在 crx/de 中,我只能看到一个节点对象: 在此处输入图像描述

我的通用 cta 对话框配置如下所示: 在此处输入图像描述

如您所见,如果我使用 sling 资源包含包含 CTA diagloc,它总是给我对象名称 CTA,并且它是重复的,因此新组件中的选项卡 3 和选项卡 4 对话框配置会覆盖彼此的值。

我想知道以前有人遇到过这个问题吗?什么是最好的解决方案?一些编码示例会有所帮助谢谢

4

1 回答 1

0

在提交之前重命名变量并将数据保存在单独的选项卡节点下:

// add .tab-class and tab-name in dialog so they are available as html atribute on dialog render

$(document).on("click", ".cq-dialog-submit", function (e) {
  var $tabs = $(".tab-class");

  $tabs.each(function (i) {
    var _this = $(this);
    var tabName = _this.data("tabe-name");

    _this.find("input").each(function () {
      $input = $(this);
      var existingName = $input.attr("name");
      var newName = tabName + '/' + existingName;
      $input.attr("name", newName);
    });
  });
});

同样在对话框加载调用 < componentNode >.json 并将数据从 json 正确填充到字段中,由于名称不匹配,现有数据将不再正确填充

于 2021-08-17T08:39:40.477 回答