我的组件对话框中有一个选择框,有四个选项:
- 关闭
- 默认
- 插件
- 覆盖
在对话框中,我想根据 URL 路径是否包含特定字符动态地将 defaultValue
属性设置为“off”或“default”。这可能吗?
这里是dialog.xml 片段,其中包含我尝试执行此操作的监听器:
<extra_meta_description_tag_mode
jcr:primaryType="cq:Widget"
defaultValue=""
fieldLabel="SEO Description Usage"
name="./extraMetaDescriptionTagMode"
type="select"
xtype="selection">
<listeners
jcr:primaryType="nt:unstructured"
defaultValue="function(url) {
url.contain("en_gb/news") ? return "default" : return "off";
}"/>
<options jcr:primaryType="cq:WidgetCollection">
<off
jcr:primaryType="nt:unstructured"
text="Off"
value="off"/>
<default
jcr:primaryType="nt:unstructured"
text="Append pre-set text"
value="default"/>
<addon
jcr:primaryType="nt:unstructured"
text="Append input text"
value="addon"/>
<over_write
jcr:primaryType="nt:unstructured"
text="Overwrite"
value="overwrite"/>
</options>
</extra_meta_description_tag_mode>
最佳答案
监听器只能有事件值,defaultValue 不是一个。您可以使用 loadContent 事件,该事件在对话框加载时触发。 CQ.WCM.getPagePath()
将给出当前页面路径:
<listeners
jcr:primaryType="nt:unstructured"
loadcontent="function(selection,record,path) {
var currentPath = CQ.WCM.getPagePath();
if(currentPath.indexOf('en_gb/news')!=-1)
{
selection.setValue('default');
} else {
selection.setValue('off');
}"/>
这将在每次对话框加载时重置该值,因此如果用户覆盖了默认值,您将添加条件来阻止它。
关于extjs - CQ5,使用extjs在组件对话框中动态设置 'defaultValue'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27059863/