【问题标题】:Populating select-box options on changing pathfield in dialog of Adobe cq5在 Adob​​e cq5 对话框中更改路径字段时填充选择框选项
【发布时间】:2014-09-07 07:28:44
【问题描述】:

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

我使用了侦听器并为“pathfield”字段添加了事件“change”和“dialogclose”的函数。

我可以调用 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" />

【问题讨论】:

    标签: aem


    【解决方案1】:

    您可以使用选择 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"
     }
    
    ]
    

    参考:http://dev.day.com/docs/en/cq/5-6/widgets-api/index.html?class=CQ.form.Selection

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-28
      • 1970-01-01
      • 2014-02-26
      • 2012-05-17
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-20
      相关资源
      最近更新 更多