Aem 填充Adobe cq5对话框中更改路径字段的选择框选项

Aem 填充Adobe cq5对话框中更改路径字段的选择框选项,aem,Aem,在我的一个对话框中,我有一个xtype为“pathfield”的字段。根据此字段的值,我想更改“选择框”(xtype=“selection”,type=“select”)的选项 我使用了监听器,并在事件“change”和“dialogclose”上为“pathfield”字段添加了一个函数 我可以调用servlet,它发送带有选项的JSON响应,但是,我无法用这些选项填充选择框 下面是dialog.xml的代码 <select-product jcr:primaryType="cq:Wid

在我的一个对话框中,我有一个xtype为“pathfield”的字段。根据此字段的值,我想更改“选择框”(xtype=“selection”,type=“select”)的选项

我使用了监听器,并在事件“change”和“dialogclose”上为“pathfield”字段添加了一个函数

我可以调用servlet,它发送带有选项的JSON响应,但是,我无法用这些选项填充选择框

下面是dialog.xml的代码

<select-product jcr:primaryType="cq:Widget"
                fieldDescription="Select Product (Product Details Page)"
                fieldLabel="Select Product" 
                height="{Long}40" key="productPath"
                name="./productPath" 
                style="height:21px" 
                width="{Long}350"
                rootPath="/content/MY_MSM_PATH" 
                xtype="pathfield">

    <listeners jcr:primaryType="nt:unstructured"
        change="function(){ var selectBox=$('select[name=features]');
        $.getJSON('/bin/featuresservlet?path=' + this.value, 
            function(jsonData){
                $.each(jsonData, function(i,data){
                    $('<option>').val(data.value).text(data.name).appendTo('select[name=features]');
                });
        }); }"

        dialogclose="function(){ 
            var selectBox=$('select[name=features]');
            $.getJSON('/bin/featuresservlet?path=' + this.value, function(jsonData){
                $.each(jsonData, function(i,data){
                    $('<option>').val(data.value).text(data.name).appendTo('select[name=features]');
                });
            }); }" />

</select-product> 

<features jcr:primaryType="cq:Widget" 
          fieldLabel="Select Features:"
          key="features" 
          name="./features" 
          type="select" 
          xtype="selection" />

您可以使用选择xtype的设置选项方法。将您的侦听器修改为以下内容

dialogclose="function(pathfield){ 
        var dialog = pathfield.findParentByType('dialog');
        var selectBox = dialog.findByType('selection')[0]; //assuming this is the only selection you have
        $.getJSON('/bin/featuresservlet?path=' + this.value, function(jsonData){
            selectBox.setOptions(jsonData);
            selectBox.doLayout(flase,false);
        }); }" 
servlet返回的数据必须采用以下格式:

[
 {
    "value": "valueOfOption1",
    "text": "textOfOption1"
 },
 {
    "value": "valueOfOption2",
    "text": "textOfOption2"
 }

]
参考: