[英]CQ5, dynamically set 'defaultValue' in component's dialog using extjs?
我的组件对话框中有一个选择框,其中包含四个选项:
在对话框中,我想根据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不能为1。 您可以使用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');
}"/>
这将在每次加载对话框时重置该值,因此,如果用户已覆盖默认值,则您将具有添加条件以防止该值。
您还可以为组件提供一个itemId属性,其值为:“ extra_meta_description_tag_mode”,然后编写一个ExtJS插件并将其注册为xtype:“ selection”,然后在插件的init方法中,根据当前页面路径设置defaultValue属性。 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.