【问题标题】:CQ/AEM extjs get selection dropdown box text, and get page pathCQ/AEM extjs 获取选择下拉框文本,并获取页面路径
【发布时间】:2017-02-11 14:15:49
【问题描述】:

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

现在在对话框中我有类似

我希望将$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();这将正确地获得与选择相关的值,但我不需要值,我只想getText(),并在extjs中获得当前的$PATH

其他问题,你可能注意到$.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json$PATH?selectedDevice=' + selected + '&amp;colour=red'

我如何跳过这个listner中的&,就好像我直接使用&,项目甚至不会构建。一定有办法跳过 & 让 extjs 当作字符串的一部分来发送请求

以前有人经历过吗?请提供代码示例。
谢谢

【问题讨论】:

    标签: extjs dialog selection aem


    【解决方案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);
        });
    }
    

    【讨论】:

    • 第二部分获取资源工作的路径 100% 正常 :) 但第一部分没有获得选定的文本,还有其他建议吗?谢谢
    • @seph 您是否修改了处理函数以采用两个参数而不是一个参数?即function(pathfield, value)
    • 嗨米克,是的,我做到了,我认为问题可能是......它不是dialog.xml中的硬编码选项,而是实际上是当用户单击下拉框时,对话框调用servlet,然后servlet 返回一堆数据,然后对话框呈现选项列表。因此,当对话框在调用 servlet 之前第一次初始化时,选择框根本没有选项......这可能是问题吗?我在说傻话吗……
    • 请看看我更新的答案。注意:我建议您不要将选项标签传递给您的 servlet,而是传递值(选项标签仅用于 UI)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 2016-07-28
    • 2012-05-11
    • 2010-09-05
    • 1970-01-01
    相关资源
    最近更新 更多