lundi 25 décembre 2017

Extjs Record.get from Store

Using ExtJS 4.2.3. I have FORM with combobox field and some values inside on choose, and some textfields. I need to get value from store and put it in textfields when user pick 1 of the value in combobox. Using documentForm_window.query('textfield[name="Textfield1"]')[0].setValue(record.get("cfo_name")) in listener of combobox field. But it doesn't work.

Example of code on ExtJS:

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,
                    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) {
                                            documentForm_window.query('textfield[name="Textfield1"]')[0].setValue(record.get("cfo_name"));
                                            documentForm_window.query('textfield[name="Textfield2"]')[0].setValue(record.getData().cfo_manager);

                                  }
                          });
                     }
             },
            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();
}

Example of storage. And it's code below the image. enter image description here

  //stores //   
     document_store = new Ext.data.ArrayStore({
        fields: ["document_type", "document_type_name"],
        data: [[0, "data1"], [1, "data2"], [2, "data3"]]   
    });



  OrderLines_store = new Ext.data.Store({
            model: "OrderLine_model",
            proxy: {
                url: Ext.state.Manager.get("MVC_url") + "/OrderLine/ListForDocuments",
                type: "ajax",
                reader: { root: "data" }
            },
            sorters: [{
                property: "orderLine_id",
                direction: "ASC"
            }],
            remoteFilter: true,
            filters: [{
                property: "order_GUID",
                value: [" = ''" + treasury_GUID + "''"]
            }],
            autoLoad: true
        });




Aucun commentaire:

Enregistrer un commentaire