Extjs Catch选择事件(组合框)

时间:2017-12-20 10:45:00

标签: javascript web extjs combobox extjs4

使用ExtJS 4.2.3。我有FORM组合框和一些值在里面选择。当用户在组合框中选择1的值时,我需要捕获事件。 请求语法帮助,例如获取ALERT选择DATA3值。 组合框字段的名称 - " document_type "。

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

很抱歉,我添加的部分代码是屏幕上显示错误的原因&#34;看起来您的帖子主要是代码&#34;。

1 个答案:

答案 0 :(得分: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));
            }
        });
    }
}