extjs如何将字段绑定到另一个现有表单

时间:2017-04-11 07:35:54

标签: forms extjs filefield

我有一个表单A,其中包含一些关于问题的字段(我的应用程序中的模型),但它不能通过form.getForm()。submit()直接提交。表单A中的按钮将打开另一个窗口,并且该窗口上的字段。我想将字段附加到表单A,所以我可以将这些字段一起提交。 细节如下: enter image description here

1 个答案:

答案 0 :(得分:1)

在这种情况下,我会尝试给表单提供两个不同的ID。接下来,从中检索值并合并如果字段名称不同。

var first_form_values = Ext.getCmp('first-form').getForm().getValues();
var second_form_values = Ext.getCmp('second-form').getForm().getValues();
var all_values = Ext.Object.merge(first_form_values , second_form_values); 

然后你拥有所有的值,你可以通过Ext.Ajax等发送它们。

完整示例:

Ext.create('Ext.window.Window', {
        title: 'First Form',
        height: 200,
        width: 400,
        layout: 'fit',
        items: {  
            xtype: 'form',
            id: 'first-form',
            items: [
                {
                    xtype: 'textfield',
                    fieldLabel: 'First field',
                    name: 'first-field',
                }
            ]
        },
        buttons: [
            {
                text: 'Show second form'
                handler: function()
                {
                    Ext.create('Ext.window.Window', {
                        title: 'Second Form',
                        height: 200,
                        width: 400,
                        layout: 'fit',
                        items: {  
                            xtype: 'form',
                            id: 'second-form',
                            items: [
                                {
                                    xtype: 'textfield',
                                    fieldLabel: 'Second field',
                                    name: 'second-field',
                                }
                            ]
                        },
                        buttons: [
                            {
                                text: 'Submit'
                                handler: function()
                                {
                                    var first_form = Ext.getCmp('first-form'),
                                        second_form = Ext.getCmp('second-form');
                                    if(first_form && second_form)
                                    {
                                        var fist_form_values = first_form.getForm().getValues(),
                                            second_form_values = second_form.getForm().getValues();

                                        var values = Ext.Object.merge(fist_form_values, second_form_values);  

                                        // You have all values from two forms
                                    }


                                }
                            }
                        ]
                    }).show();
                }
            }
        ]
    }).show();
相关问题