CQ5 - Dynamically populating options in selection xtype

风流意气都作罢 提交于 2019-12-21 05:35:16

问题


I've been banging my head for hours on this now. I'm trying to dynamically populate options in a selection xtype and can't get it to work. Here is my 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>

The json that I'm producing for:

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

Looks something like this:

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

When I go to open the dialog nothing happens I just get a JS error TypeError: snippet.xtype is undefined

Any help is appreciated!


回答1:


Options for the selection xtype can be set dynamically in two ways

  1. setting the options property to a path that returns a JSON array of options
  2. Writing a function that sets the options (using setOptions method ) and passing this function as the value for optionsProvider property.

In both the cases data returned in JSON must be an array.

To use method 1 , on the headerType node set options property to the path that will provide the JSON data. Set optionsRoot proprety to the name of the property that contains the JSON array. Set optionsTextField to the name of the property in the JSON data that should be text. Set optionsValueField to the name of the property in the JSOn data that should be the value.

A detailed tutorial on this can be found here : http://jenikya.com/blog/2013/04/dynamic-dialog-data-in-cq5.html

For method 2 refer this



来源:https://stackoverflow.com/questions/27698220/cq5-dynamically-populating-options-in-selection-xtype

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!