我有以下代码库与您分享列出通过
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获取选项.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。