【问题标题】:can't load data from Grid to new Window with Form Extjs 4无法使用 Form Extjs 4 将数据从网格加载到新窗口
【发布时间】:2016-02-17 01:47:33
【问题描述】:

我在将数据从网格加载到 Extjs 4 中的表单时遇到问题。

我正在尝试将字段 vid 发送到表单,只是为了测试,但我什至不能这样做。找到了很多例子,尝试了这些想法。做不到。

数据来自mongodb。

我可以完美地在网格中显示它。

现在我想点击编辑按钮打开一个带有表单的窗口并显示信息。

我错过了什么?

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

【问题讨论】:

    标签: javascript node.js mongodb extjs


    【解决方案1】:

    在渲染方法之后试试这个:

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

    希望它有效。

    【讨论】:

    • 没有,但感谢您的帮助。将尝试使用此建议的其他方法
    【解决方案2】:

    当您创建窗口时,它会被渲染(DOM 在后台某处构建)但尚未设置 window.record。

    但处理程序设置win.record后,窗口不会重新渲染,只显示。

    因此,如果您从 afterrender 切换到 beforeshow 事件,它应该可以工作,每次调用 win.show() 时都会执行该事件。

    此外,window.record 包含记录的索引,而不是记录本身;但是loadRecord 需要记录,而不是索引。试试win.record = grid.getStore().getAt(rowIndex);之类的,loadRecord`应该可以加载记录了。

    【讨论】:

    • 做了,没用。我需要在表格方面做些什么吗?映射数据。
    • 我仔细查看了您的代码,不得不承认我忽略了另一个错误。我会编辑我的帖子。
    猜你喜欢
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    相关资源
    最近更新 更多