CQ5 - 在选择xtype中动态填充选项

Del*_*ung 3 sling aem

我现在一直在敲打几个小时.我正在尝试动态填充选择xtype中的选项,但无法使其工作.这是我的dialog.xml

<resourceType
            jcr:primaryType="cq:Panel"
            title="Header Type">
            <items jcr:primaryType="cq:WidgetCollection">
                <headerType
                        jcr:primaryType="cq:Widget"
                        fieldLabel="Header Type"
                        name="./headerType"
                        type="select"
                        xtype="selection">
                    <options jcr:primaryType="cq:WidgetCollection">
                        <categories
                            jcr:primaryType="cq:Widget"
                            path="/content/admin/adminView/jcr:content/header-admin-content/cats/type.infinity.json"
                            width="500"
                            xtype="cqinclude" />
                    </options>
                </headerType>
            </items>
        </resourceType>
Run Code Online (Sandbox Code Playgroud)

我正在制作的json:

content/admin/adminView/jcr:content/header-admin-content/cats/type.infinity.json
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

{"jcr:primaryType":"nt:unstructured","item_1":  
{"jcr:primaryType":"nt:unstructured","text":"small","parameter":"small"},"item_2":
{"jcr:primaryType":"nt:unstructured","text":"medium","parameter":"medium"},"item_3":
{"jcr:primaryType":"nt:unstructured","text":"large","parameter":"large"},"item_4":
{"jcr:primaryType":"nt:unstructured","text":"none","parameter":"none"}} 
Run Code Online (Sandbox Code Playgroud)

当我打开对话框时没有任何反应我只是得到一个JS错误TypeError:snippet.xtype是未定义的

任何帮助表示赞赏!

Sha*_*ppa 7

selection可以通过两种方式动态设置xtype的选项

  1. options属性设置为返回JSON选项数组的路径
  2. 编写一个设置选项的函数(使用setOptions方法)并将此函数作为optionsProvider属性的值传递.

在这两种情况下,JSON返回的数据必须是一个数组.

要使用方法1,请在headerType节点上将 set options属性设置为将提供JSON数据的路径.将optionsRootproprety 设置为包含JSON数组的属性的名称.设置optionsTextField为应为文本的JSON数据中的属性名称.设置optionsValueField为JSOn数据中应该是值的属性的名称.

有关这方面的详细教程可以在这里找到:http://jenikya.com/blog/2013/04/dynamic-dialog-data-in-cq5.html

对于方法2,请参阅