【问题标题】:CQ5, dynamically set 'defaultValue' in component's dialog using extjs?CQ5,使用extjs在组件对话框中动态设置'defaultValue'?
【发布时间】:2014-11-21 11:05:14
【问题描述】:

我的组件对话框中有一个选择框,有四个选项:

  • 关闭
  • 默认
  • 插件
  • 覆盖

在对话框中,我想根据 URL 路径是否包含特定字符,将defaultValue 属性动态设置为“关闭”或“默认”。这可能吗?

这是 dialog.xml sn-p 与我尝试执行此操作的侦听器:

<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>

【问题讨论】:

  • URL路径是指当前页面的路径还是别的什么意思?
  • ye,当前页面的路径,例如 /content/sometestweb/en-gb/news/testnews.html

标签: extjs dialog content-management-system components aem


【解决方案1】:

监听器只能有事件的值,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');
        }"/>

这将在每次对话框加载时重置该值,因此如果用户覆盖了默认值,您将添加条件来防止它。

【讨论】:

    【解决方案2】:

    你也可以给你的组件一个 itemId 属性,其值为:“extra_meta_description_tag_mode”,然后编写一个 ExtJS 插件并将其注册为 xtype:“selection”,并在插件的 init 方法中,根据当前页面路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多