extjs - CQ5,使用extjs在组件对话框中动态设置 'defaultValue'?

标签 extjs dialog content-management-system components aem

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

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

在对话框中,我想根据 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/

相关文章:

extjs - 如果我将在 extjs 中单击消息框的"is"或“否”按钮,如何从一个页面转移到另一个页面?

asp.net - 我们应该在 CMS 之上构建复杂的应用程序吗?

javascript - 有没有办法让 ExtJS GridPanel 自动调整其宽度,但仍包含在一些非 ExtJS 生成的 HTML 中?

javascript - ExtJS中 bool 字段排序选择什么方向类型?

javascript - 我如何使用 sencha 选项卡上的按钮来放置覆盖面板

java - 对话框中的 println 带有非拉丁符号

dialog - Flutter,如何删除对话框周围的空格?

jquery - $(...).on 不是函数 - jQuery 错误

drupal - 如何在 Drupal 中创建具有三个细节层的时间线?

ruby-on-rails - Ruby on Rails内容管理系统?