【问题标题】:CQ5 - Dynamically populating options in selection xtypeCQ5 - 在选择 xtype 中动态填充选项
【发布时间】:2014-12-30 00:56:44
【问题描述】:

我已经为此绞尽脑汁好几个小时了。我正在尝试在选择 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>

我正在生成的 json:

content/admin/adminView/jcr:content/header-admin-content/cats/type.infinity.json

看起来像这样:

{"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"}} 

当我打开对话框时没有任何反应,我只是收到一个 JS 错误 TypeError: sn-p.xtype is undefined

感谢任何帮助!

【问题讨论】:

    标签: aem sling


    【解决方案1】:

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

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

    在这两种情况下,以 JSON 格式返回的数据都必须是一个数组。

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

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

    方法二请参考this

    【讨论】:

    • 似乎已经找到了 options 属性,但出于某种原因,我认为 optionsRoot 让我感到困惑。在上面我发布的 json 中,optionsRoot 是什么?还是我需要创建一个包含上述 json 的特定选项属性?感谢您的帮助!
    • 你将不得不修改 json ,它需要一个 array 。当前形式中没有数组或根
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 2011-12-26
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多