加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax – 如何在CQ5中添加包含页面列表的下拉列表?

发布时间:2020-12-16 02:53:24 所属栏目:百科 来源:网络整理
导读:我有以下代码库与您分享列出通过 AJAX调用使用查询构建器获取的页面.我们必须传递URL和参数以从我们提供的URL中获取子页面. 我已经放了一些console.log来跟踪每个状态的值. 替换你的项目. featurearticles jcr:primaryType="cq:Widget" fieldLabel="Article
我有以下代码库与您分享列出通过 AJAX调用使用查询构建器获取的页面.我们必须传递URL和参数以从我们提供的URL中获取子页面.

我已经放了一些console.log来跟踪每个状态的值.
替换你的项目.

<featurearticles
    jcr:primaryType="cq:Widget"
    fieldLabel="Article Pages"
    itemId="selectauthorId"
    name="./authorselect"
    type="select"
    xtype="selection">
    <options jcr:primaryType="cq:WidgetCollection"/>
    <listeners
        jcr:primaryType="nt:unstructured"
        loadcontent="function(box,value) { 
        CQ.Ext.Ajax.request({ 
            url: '/bin/querybuilder.json',success: function(response,opts) { 
                console.log('Response from the ajax'); 
                var resTexts = $.parseJSON(response.responseText); 
                var selectopts = []; 
                console.log(resTexts); 
                $.each(resTexts.hits,function(key,page) { 
                    console.log(page); 
                    selectopts.push({value: page['path'],text:page['name']}); 
                }); 
                console.log(selectopts); 
                box.setOptions(selectopts); 
            },params: {
            'type' :'cq:Page','group.1_path' : '/content/<PROJECT_NAME>/Feature_Articles' 
            } 
        }); 
       }"
       selectionchanged="function(box,value) { 
        var panel = this.findParentByType('panel');
        var articleTitle = panel.getComponent('articleTitleId');

        CQ.Ext.Ajax.request({ 
            url: value + '/_jcr_content/par/featurearticleintro.json',opts) {
                console.log('success now');
                var resTexts = $.parseJSON(response.responseText); 
                console.log(resTexts);
            },failure: function(response,opts) {                    
                console.log('server-side failure with status code ' + response.status);
            }
        });            
    }"/>
</featurearticles>

如果你有更好的想法,我想知道这一点.

干杯,

解决方法

另一种方法是使用选择xtype的“options”属性,通过servlet或sling选择器从AJAX调用中获取下拉列表选项.小部件api( http://dev.day.com/docs/en/cq/5-6/widgets-api/index.html – 搜索“selection”)为options属性说明了这一点:

If options is a string it is assumed to be an URL pointing to a JSON
resource that returns the options (same structure as above applies).
This should be either an absolute URL or it can use the path of the
content resource being edited using a placeholder
(Selection.PATH_PLACEHOLDER = “$PATH”),for example:
$PATH.options.json.

因此,构建一个将使用JSON响应AJAX请求的servlet可能是一种更简洁的方法,然后将此servlet作为“options”属性.例如,属性可能类似于options =“/ libs / myServlet”或类似options =“$PATH.options.json”.这可能会使对话更清晰(不需要监听器),并且它使用内置的CQ功能通过AJAX获取选项.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读