2017-12-20 3 views
0

ExtJS 4.2.3 사용. 나는 콤보 박스 필드와 내부에있는 몇 가지 값을 가지고 FORM을 가지고있다. 사용자가 콤보 상자에서 값 1을 선택할 때 이벤트를 잡아야합니다. DATA3 값을 선택하면 ALERT를받는 예제와 같이 구문에 대한 도움말을 요청합니다. 콤보 상자 이름의 필드 - "document_type". 의 ExtJS에 코드의Extjs 이벤트 선택 (combobox)

예 :

enter image description here

 documentForm_window = Ext.create("Ext.window.Window", { 
      title: (document_GUID == null) ? "[Create]" : "[Edit]", 
      width: 500, 
      modal: true, 
      layout: "fit", 
      items: [{ 
       xtype: "form", 
       frame: true, 
       waitMsgTarget: true, 
       listeners: { 
        afterrender: function (form) { 
         if (document_GUID != null) { 
          form.getForm().load({ 
           url: Ext.state.Manager.get("MVC_url") + "/Document/Get", 
           method: "GET", 
           params: { document_GUID: document_GUID }, 
           waitMsg: "[loading]", 
           timeout: 300, 
           failure: function (form, action) { 
            if (action.result) Ext.Msg.alert("[Error1]!", action.result.errorMessage); 
            else Ext.Msg.alert("[Error2]!", "[Error3]!"); 
           } 
          }); 
         } 
        } 
       }, 
       defaults: { 
        anchor: "100%", 
        msgTarget: "side", 
        labelWidth: 145, 
        allowBlank: false 
       }, 
       items: [{ 
        xtype: "combo", 
        name: "document_type", 
        fieldLabel: "<b>[Type]<font color='Red'>*</font></b>", 
        displayField: "document_type_name", 
        valueField: "document_type", 
        queryMode: "local", 
        triggerAction: "all", 
        editable: false, 
        store: document_store 
       }, { 
        xtype: "textfield", 
        name: "contract_number", 
        fieldLabel: "<b>[TestData]</b>" 

       }], 
       formBind: true, 
       buttons: [{ 
        text: (document_GUID == null) ? "[Create]" : "[Edit]", 
        handler: function() { 
         var action = (document_GUID == null) ? "Create" : "Edit"; 

         var form = this.up("form").getForm(); 
         if (form.isValid()) { 
          form.submit({ 
           url: Ext.state.Manager.get("MVC_url") + "/Document/" + action, 
           params: { document_GUID: document_GUID, treasury_GUID: tree_value }, 
           waitMsg: "[Loading...]", 
           success: function (form, action) { 
            documentForm_window.destroy(); 
            OrderLines_store.load({ 
             scope: this, 
             callback: function (records, operation, success) { 
              documents_List.query('*[itemId="DATA1_grid"]')[0].selModel.select(curr_position); 
             } 
            }); 
           }, 
           failure: function (form, action) { 
            if (action.result) Ext.Msg.alert("[Error1]!", action.result.msg); 
            else Ext.Msg.alert("[Error2]!", "[Error3]!"); 
           } 
          }); 
         } 
        } 
       }] 
      }] 
     }).show(); 
    } 
//store// 
    document_store = new Ext.data.ArrayStore({ 
     fields: ["document_type", "document_type_name"], 
     data: [[0, "data1"], [1, "data2"], [2, "data3"]] 
    }); 

미안 해요, 난 후 에러 화면 원인으로 추가하는 코드의 일부는 "게시물은 대부분 코드 것 같습니다."

답변

1

당신은 콤보 상자에 select event 청취자를 추가해야합니다 :

editable: false, 
store: document_store, 
listeners: { 
    select: function(combo, records) { 
     console.log(combo); 
     console.log(records); 
     if(!Ext.isArray(records)) records = [records]; 
     Ext.each(records, function(record) { 
      if(record.get(combo.valueField)==3) { 
       Ext.Msg.alert('Value is 3 for' + record.get(combo.displayField)); 
      } 
     }); 
    } 
} 
+0

들으, 그것은 잘 작동합니다. 선택에 대한 알리미를 얻으려는 예를 도울 수 있습니까? 나는 이것을 시도했다. if (Documents_List.query ('field [name = "document_type"]') [0] .getValue() == 3 { Ext.Msg.alert ("TEST") }' 나던. – Dmitry

+1

나는 내 대답을 수정했다. – Alexander

+0

정말 고마워요! – Dmitry