简体   繁体   English

无法使用Form Extjs 4将数据从网格加载到新窗口

[英]can't load data from Grid to new Window with Form Extjs 4

i'm having an issue loading data from a grid to a form in Extjs 4. 我在将数据从网格加载到Extjs 4中的表单时遇到问题。

I'm trying to send the field vid to the form, just for testing but I can't even do that. 我试图将字段vid发送到表单,仅用于测试,但我什至不能这样做。 Found lots of examples, tried the ideas. 找到了很多例子,尝试了这些想法。 can't do it. 做不到。

The data comes from mongodb. 数据来自mongodb。

I can show it in a grid perfectly. 我可以完美地在网格中显示它。

And now I want to click in the Edit Button to open a window with a form and show the information. 现在,我想单击“编辑”按钮以打开带有表单的窗口并显示信息。

What am I missing? 我想念什么?

Ext.define('DevJS.view.users.List', {
    extend: 'Ext.grid.Panel',
    autoHeight: true,
    forceFit: true,
     this.columns = [
                {text: 'Id', dataIndex: '_id', hidden: true},
                {
                    text: 'Vid',
                    dataIndex: 'vid',
                    autoSizeColumn: true

                }
    ...
    xtype: 'actioncolumn',
                        autoSizeColumn: true,
                        items: [
                            {
                                iconCls: 'button-edit',
                                tooltip: 'Edit',
                                handler: function (grid, rowIndex, colIndex) {
                                    this.up('grid').fireEvent('editRow', grid, rowIndex, colIndex);
                                }
                            },
                            {
                                iconCls: 'button-info',
                                itemId: 'Comments',
                                text: 'Comments',
                                handler: function (grid, rowIndex, item) {
                                    alert(rowIndex)
                                    win.record = rowIndex;

                                    win.show()
                                }
                            }
                        ]
                    }
                ];

                //parent
                this.callParent(arguments);
            }
        });

        var form = new Ext.form.FormPanel({
            title : 'Test form',
            id:'form',
            width : 300,
            items : [{
                xtype: 'textfield',
                editable:false,
                fieldLabel: 'vid',
                name: 'vid'
            }]
        });

        var win = new Ext.Window({
            title : 'test',
            items : [{
                xtype : 'panel',
                layout : 'column',
                items : [form]
            }],
            listeners:{
                afterrender:function(window) {
                    if(window.record) window.down('form').loadRecord(window.record);
                }
            }
        });

just try this at after render method : 只需在render方法之后尝试一下即可:

if(window.record) window.down('form').getForm().loadRecord(window.record);

hope it works. 希望它能工作。

When you create the window, it is rendered (the DOM is built somewhere in the background) but window.record is not yet set. 创建窗口时,将渲染该窗口(DOM在背景中的某个位置生成),但尚未设置window.record

But after the handler sets win.record , the window is not rerendered, only shown. 但是在处理程序设置win.record ,不重新渲染窗口,仅显示该窗口。

So it should work if you switch from the afterrender to beforeshow event, which is executed every time win.show() is called. 因此,如果您从afterrender切换到beforeshow事件,则该方法应该起作用,该事件在每次调用win.show()时执行。

Furthermore, window.record contains the index of the record, not the record itself; 此外, window.record包含记录的索引,而不是记录本身。 but loadRecord takes a record, not an index. 但是loadRecord需要一条记录,而不是索引。 Try sth like win.record = grid.getStore().getAt(rowIndex); 尝试像win.record = grid.getStore().getAt(rowIndex); and loadRecord` should be able to load the record. 和loadRecord`应该能够加载记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM