CQ/AEM extjs获取选择下拉框文本,并获取页面路径

CQ/AEM extjs get selection dropdown box text, and get page path

假设我有一个组件,在内容页面上有一个对话框下拉到 parsys /content/phonegap/ss/en_gb/login/home/test1/jcr:content/par/productimage

现在在对话框中我有类似

的内容

我希望将 $PATH 附加到 URL 并发送 selected 设备,例如文本 '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(),并且在 extjs.

中获取当前 $PATH

另外一个问题,你可能注意到了$.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json$PATH?selectedDevice=' + selected + '&colour=red'

如何跳过此监听器中的 &,就像我直接使用 & 一样,项目甚至不会构建。必须有办法跳过 & 让 extjs 把它当作字符串的一部分来发送 request

有人以前遇到过这个吗?请提供代码示例。
谢谢

获取选项的文本被选中:

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);
    });
}