2017-02-11 69 views
0

說我有一個對話,我有類似enter image description hereCQ/AEM ExtJS的獲得選擇下拉框中的文字,並獲得頁面的路徑

我裏面對話框降parsys內容網頁上/content/phonegap/ss/en_gb/login/home/test1/jcr:content/par/productimage

現在組件希望得到$PATH附加到網址和發送所選設備如文本'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> 

所以bascially,該console.log(this.findParentByType('form').find('name', './deviceAndColour')[0].getText());沒有工作,我EXPEC ted,對話框監聽器js裏面的$PATH都沒有,它根本不檢索路徑。

除了上面的嘗試,我知道var selected = this.findParentByType('form').find('name', './deviceAndColour')[0].getValue();這將讓與正確的選擇asscociated的價值,但我不需要值,我只想getText(),並在ExtJS的獲取當前$PATH

另一個問題,你可以注意到$.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json$PATH?selectedDevice=' + selected + '&colour=red'

我怎麼跳過&在這個聽者,因爲如果我使用&直接,項目甚至不會建立。必須有一些跳過&,並讓extjs視爲字符串的一部分發送請求

以前有誰曾經這樣做過?請使用代碼示例進行推薦。
感謝

回答

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

UPDATE

請嘗試下面的代碼,以適應您的情況(我也重構了代碼,以便在提供查詢參數時使用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); 
    }); 
} 
+0

第二部分獲取資源工作路徑100%罰款:)但第一部分沒有得到選定的文本,任何其他建議?謝謝 – seph

+0

@seph你是否修改了你的處理函數來取代兩個參數? ie'function(pathfield,value)' – mickleroy

+0

嗨米克,是的,我做了,我認爲這個問題可能是...它不是在dialog.xml中的硬編碼選項,相反,它實際上是當用戶點擊下拉框,對話框調用servlet ,然後servlet返回一堆數據,然後對話框渲染選項列表。所以當對話在調用servlet之前第一次初始化時,根本沒有選擇框的選項....那可能是問題嗎?我是在說傻... – seph