Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ExtJS:网格和;类型_Javascript_Extjs_Extjs6 Classic - Fatal编程技术网

Javascript ExtJS:网格和;类型

Javascript ExtJS:网格和;类型,javascript,extjs,extjs6-classic,Javascript,Extjs,Extjs6 Classic,我正在努力学习ExtJS,我有点被困在一个地方。我想创建一个屏幕,顶部有一个网格,底部有一个窗体。我想将它们彼此绑定,这样当我从网格中选择一行时,表单字段会被填充(在网格中使用相同的记录),当我更改网格或表单中的任何内容时,另一侧会被更新 到目前为止,我有一个带有网格和窗体的视图。我有一个向网格提供数据的存储。我被困在这里了。如何在表单和网格之间进行双向绑定。我试过谷歌,找到了一些样本,但它们都是单向绑定的。i、 e.如果我在网格上执行以下操作: listeners: {

我正在努力学习ExtJS,我有点被困在一个地方。我想创建一个屏幕,顶部有一个网格,底部有一个窗体。我想将它们彼此绑定,这样当我从网格中选择一行时,表单字段会被填充(在网格中使用相同的记录),当我更改网格或表单中的任何内容时,另一侧会被更新

到目前为止,我有一个带有网格和窗体的视图。我有一个向网格提供数据的存储。我被困在这里了。如何在表单和网格之间进行双向绑定。我试过谷歌,找到了一些样本,但它们都是单向绑定的。i、 e.如果我在网格上执行以下操作:

           listeners: {

                selectionchange: function(model, records) {
                    var rec = records[0];
                    var form = Ext.getCmp('chartofaccountsForm');
                    form.loadRecord(rec);
                }
            }
它只使用当前选择的记录填充表单,但当我在表单中更新记录时,网格不会更新

谁能帮我指出正确的方向吗?任何教程或博客文章都会非常有帮助

尝试以下示例:

Ext.widget('container',{
        width: 600,
        hight: 800,
        renderTo: Ext.getBody(),
        viewModel: {
            formulas: {
                selection: {
                    bind: '{g.selection}',
                    get: function(selection){
                        return selection;
                    }
                }
            }
        },
        items: [
            {
                xtype: 'grid',
                title: 'Grid',
                reference: 'g',
                store: {
                    type: 'store',
                    fields: ['id', 'name'],
                    data: [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
                },
                columns: [
                    {dataIndex: 'id', header: 'ID'},
                    {dataIndex: 'name', header: 'Name'}
                ]
            },
            {
                xtype: 'form',
                title: 'Form',
                items: [
                    {
                        xtype: 'displayfield',
                        fieldLabel: 'ID',
                        bind: '{selection.id}'
                    },
                    {
                        xtype: 'textfield',
                        fieldLabel: 'Name',
                        bind: '{selection.name}'
                    }
                ],
                bind: {
                    hidden: '{!selection}'
                }
            }
        ]

    });

试试这个例子:

Ext.widget('container',{
        width: 600,
        hight: 800,
        renderTo: Ext.getBody(),
        viewModel: {
            formulas: {
                selection: {
                    bind: '{g.selection}',
                    get: function(selection){
                        return selection;
                    }
                }
            }
        },
        items: [
            {
                xtype: 'grid',
                title: 'Grid',
                reference: 'g',
                store: {
                    type: 'store',
                    fields: ['id', 'name'],
                    data: [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
                },
                columns: [
                    {dataIndex: 'id', header: 'ID'},
                    {dataIndex: 'name', header: 'Name'}
                ]
            },
            {
                xtype: 'form',
                title: 'Form',
                items: [
                    {
                        xtype: 'displayfield',
                        fieldLabel: 'ID',
                        bind: '{selection.id}'
                    },
                    {
                        xtype: 'textfield',
                        fieldLabel: 'Name',
                        bind: '{selection.name}'
                    }
                ],
                bind: {
                    hidden: '{!selection}'
                }
            }
        ]

    });