CQ5-在选择xtype中动态填充选项 [英] CQ5 - Dynamically populating options in selection xtype
问题描述
现在,我已经为此努力了好几个小时。我正在尝试动态填充选择xtype中的选项,但无法使其正常工作。这是我的dialog.xml
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>
我为之生成的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:snippet.xtype未定义
When I go to open the dialog nothing happens I just get a JS error TypeError: snippet.xtype is undefined
我们将为您提供任何帮助!
Any help is appreciated!
推荐答案
xtype 选择
的选项可以动态设置两种方式
Options for the selection
xtype can be set dynamically in two ways
- 设置选项属性指向返回选项JSON数组的路径
- 编写一个设置选项的函数(使用 setOptions 方法),然后将此函数作为 optionsProvider 属性。
- setting the options property to a path that returns a JSON array of options
- Writing a function that sets the options (using setOptions method ) and passing this function as the value for optionsProvider property.
在两种情况下,以JSON返回的数据都必须是数组。
In both the cases data returned in JSON must be an array.
要使用方法1,请在 headerType 节点上将 options
属性设置为路径将提供JSON数据。将 optionsRoot
属性设置为包含JSON数组的属性的名称。将 optionsTextField
设置为JSON数据中应为文本的属性的名称。将 optionsValueField
设置为JSOn数据中应为其值的属性的名称。
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.
有关可以在这里找到: http:// jenikya。 com / blog / 2013/04 / dynamic-dialog-data-in-cq5.html
A detailed tutorial on this can be found here : http://jenikya.com/blog/2013/04/dynamic-dialog-data-in-cq5.html
有关方法2,请参见此
这篇关于CQ5-在选择xtype中动态填充选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!