2017-12-20 8 views
0

ExtJS 4.2.3を使用する。私は、コンボボックスフィールドといくつかの値を内部に選択してフォームを持っています。私は、ユーザーがコンボボックスの値のうち1つを選択したときにイベントを捕捉する必要があります。 DATA3値をピックする際にALERTを得る例として、構文の助けを求める。 コンボボックスフィールドの名前 - 「document_type」。 ExtJSの上のコードのExtjsイベントを捕捉する(コンボボックス)

例:

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"]] 
    }); 

申し訳ありませんが、コードの一部は、私は「あなたのポストはほとんどのコードであるように見え、」ポスト・エラーの画面原因として追加します。あなたはコンボボックスにselect eventのリスナーを追加する必要が

答えて

1

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

Thxをし、それは素晴らしい作品。私はあなたに選択肢のアレルを得るための例を手伝ってもらうように頼むことができますか私はこれを試しましたif(Documents_List.query( 'field [name = "document_type"]')[0] .getValue()== 3){ Ext.Msg.alert( "TEST") } ' doesnt仕事。 – Dmitry

+1

私は私の答えを修正しました。 – Alexander

+0

ありがとう、ありがとう! – Dmitry

関連する問題