假设我在内容页/content/phonegap/ss/en_gb/login/home/test1/jcr:content/par/productimage
我希望$PATH
附加到URL并将所选设备(例如文本'Device ID:HTC_10_GOLD'
)发送到此对话框侦听器extjs中的servlet:
<deviceAndColour
jcr:primaryType="cq:Widget"
allowBlank="{Boolean}false"
fieldLabel="Device and Colour"
name="./deviceAndColour"
options="/bin/reference/data/device.devices.json$PATH"
type="select"
xtype="selection">
<listeners
jcr:primaryType="nt:unstructured"
selectionchanged="function(pathfield) {
var selected = this.findParentByType('form').find('name', './deviceAndColour')[0].getText();
console.log( this.findParentByType('form').find('name', './deviceAndColour')[0].getText());
$.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json$PATH?selectedDevice=' + selected + '&colour=red', function(jsonData){
selectBox.setOptions(jsonData);
});
}" />
</deviceAndColour>
所以基本上,console.log( this.findParentByType('form').find('name', './deviceAndColour')[0].getText());
没有按照我的预期工作,对话框监听器js中的$PATH
都没有,它根本没有检索路径。
除了上述尝试之外,我知道var selected = this.findParentByType('form').find('name', './deviceAndColour')[0].getValue();
这将获得与select正确关联的值,但我不需要值,我只希望getText()
,并获得当前{{1在extjs。
另外一个问题,您可能会注意到$PATH
如何跳过&amp;在这个列表中,好像我使用&amp;直接,项目甚至没有建立。必须有一些跳过&amp;并让extjs视为发送请求的字符串的一部分
之前有人对此事进行过探讨吗?请用代码示例建议 感谢
答案 0 :(得分:1)
选择选项的文字:
function(field,value){
for(var i = 0; i < field.options.length; i++) {
if(field.options[i].value === value) {
console.log('Selected: ' + field.options[i].text);
break;
}
}
}
获取正在编辑的资源路径:
function(field,value){
console.log("Resource:" + field.findParentByType("dialog").path);
}
文档:https://docs.adobe.com/docs/en/cq/5-6/widgets-api/index.html?class=CQ.form.Selection
<强>更新强>
请尝试以下适用于您的方案的代码(我还提供了在提供查询参数时使用params
重构的代码。没有理由说这不起作用。
function(field, value) {
var selected = '';
var path = field.findParentByType("dialog").path;
// get text of option selected
for(var i = 0; i < field.options.length; i++) {
if(field.options[i].value === value) {
selected = field.options[i].text;
break;
}
}
var params = {
selectedDevice: selected,
colour: 'red'
}
$.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json'+path, params, function(jsonData){
// FIXME: how are you getting the "selectBox" reference?
selectBox.setOptions(jsonData);
});
}