2017-08-11 115 views
0

我想知道如何從作者在給定的下拉列表中獲取選定值觸摸UI對話框使用javascript進行進一步操作。獲取由JavaScript中作者[AEM]選擇的對話框屬性值

下面是我的javascript我對話框結構

<?xml version="1.0" encoding="UTF-8"?> 
 
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" 
 
    jcr:primaryType="nt:unstructured" 
 
    sling:resourceType="cq/gui/components/authoring/dialog"> 
 
    <content 
 
     jcr:primaryType="nt:unstructured" 
 
     sling:resourceType="granite/ui/components/foundation/container"> 
 
     <layout 
 
      jcr:primaryType="nt:unstructured" 
 
      sling:resourceType="granite/ui/components/foundation/layouts/tabs" 
 
      type="nav"/> 
 
     <items jcr:primaryType="nt:unstructured"> 
 
      <General 
 
       jcr:primaryType="nt:unstructured" 
 
       jcr:title="General Questions" 
 
       sling:resourceType="granite/ui/components/foundation/container"> 
 
       <layout 
 
        jcr:primaryType="nt:unstructured" 
 
        sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns"/> 
 
       <items jcr:primaryType="nt:unstructured"> 
 
        <columns 
 
         jcr:primaryType="nt:unstructured" 
 
         sling:resourceType="granite/ui/components/foundation/container"> 
 
         <items jcr:primaryType="nt:unstructured"> 
 
          <allowed-selections 
 
           jcr:primaryType="nt:unstructured" 
 
           sling:resourceType="granite/ui/components/foundation/form/select" 
 
           fieldLabel="Allowed Selections" 
 
           name="./allowed"> 
 
           <items jcr:primaryType="nt:unstructured"> 
 
            <one 
 
             jcr:primaryType="nt:unstructured" 
 
             text="One" 
 
             value="one"/> 
 
            <two 
 
             jcr:primaryType="nt:unstructured" 
 
             text="Two" 
 
             value="two"/> 
 
            <three 
 
             jcr:primaryType="nt:unstructured" 
 
             text="Three" 
 
             value="three"/> 
 
            <four 
 
             jcr:primaryType="nt:unstructured" 
 
             text="Four" 
 
             value="four"/> 
 
           </items> 
 
          </allowed-selections> 
 
          <description/> 
 
          <selection-text 
 
           jcr:primaryType="nt:unstructured" 
 
           sling:resourceType="granite/ui/components/foundation/form/textfield"        
 
           fieldLabel="Selection Text" 
 
           name="./selectiontext"/> 
 
         </items> 
 
        </columns> 
 
       </items> 
 
      </General> 
 
     </items> 
 
    </content> 
 
</jcr:root>

在這裏,我想取./allowed(下拉)的對話框屬性值。

預先感謝您。

回答

0

AEM是一種有一個開箱即用的庫feature.If看到 etc文件夾,我們有以下文件

/庫/ CQ/GUI /組件/製作/對話框/ dropdownshowhide/clientlibs實現隱藏/顯示/dropdownshowhide/js/dropdownshowhide.js

Foundationcontentloaded,改變和選擇的事件是基於被取回

參見類名選擇器和目標元素選擇值有拍攝採樣片段

$(document).on("selected", ".dropdownselect", function(e) { 
    //iterate over e and get element select value 
}); 

$(element).data(「select」)。getValue();

添加類,數據屬性和選擇作爲其在JS,那麼你也可以使用選擇監聽器獲取選中下拉值,做你的自定義邏輯

在你的對話框添加類dropdownselect,您可以頂給定然後在變化事件中捕獲價值

<allowed-selections 
jcr:primaryType="nt:unstructured"sl 
sling:resourceType="granite/ui/components/foundation/form/select" 
fieldLabel="Allowed Selections" 
name="./allowed" 
class = "dropdownselect"> 
+1

我不確定將來其他人的絕對路徑是否會有用。您應該對解決方案進行一些擴展,以便以一般方式進行理解。 – jdv

+0

當然。我指的是我們擁有這個文件的默認位置。我將用更多的輸入來更新解決方案 – sherry

+0

我保證你在路上的某個人不會在這個位置有這個文件,這使得這個答案對他人不太有用。更不用說這個位置只是某些平臺的默認設置。請參閱:https://stackoverflow.com/help/how-to-answer – jdv