javascript - Extjs:访问窗口中链接的 Proprety Grid

标签 javascript extjs

我需要访问已创建的 NewPerson 窗口的 PropertyGrid。

  • NewPerson 窗口由属性网格和工具栏组成。
  • 当用户填写属性网格并点击“保存”按钮时,一个新的 人应该被创建为具有存在于 属性网格。
  • 问题是用户应该能够根据需要创建任意数量的 NewPerson 窗口,那么我如何访问窗口的 propertygrid?谢谢。

NewPerson 窗口 View :

Ext.define('MyApp.view.ui.NewPerson', {
    extend: 'Ext.window.Window',

    height: 180,
    width: 524,
    resizable: false
,
    layout: {
        type: 'fit'
    },
    title: 'New Person',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            dockedItems: [
                {
                    xtype: 'newpersontoolbar',
                    dock: 'bottom'
                }
            ],
            items: [
                {
                    xtype: 'newpersongrid'
                }
            ]
        });

        me.callParent(arguments);
    }

});

NewPersonGrid View :

Ext.define('MyApp.view.ui.NewPersonGrid', {
    extend: 'Ext.grid.property.Grid',

    border: 0,
    id: 'newpersongrid',
    forceFit: true,

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            source: {
                'Property 1': 'String',
                'Property 2': true,
                'Property 3': '2012-02-20T19:22:06',
                'Property 4': 123
            },
            listeners: {
                afterlayout: {
                    fn: me.onPropertyAfterLayout,
                    scope: me
                }
            }
        });

        me.callParent(arguments);
    },

    onPropertyAfterLayout: function(abstractcontainer, layout, options) {
    }

});

NewPersonToolbar View :

Ext.define('MyApp.view.ui.NewPersonToolbar', {
    extend: 'Ext.toolbar.Toolbar',


    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'savebutton'
                }
            ]
        });

        me.callParent(arguments);
    }

});

保存按钮 View :

Ext.define('MyApp.view.ui.SaveButton', {
    extend: 'Ext.button.Button',

    text: 'Save person',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            listeners: {
                click: {
                    fn: me.onButtonClick,
                    scope: me
                }
            }
        });

        me.callParent(arguments);
    },

    onButtonClick: function(button, e, options) {
      // GRID = code here to access propertygrid
      Ext.create('MyApp.model.Person', Ext.encode(GRID.getSource()));
    }

});

最佳答案

由于您的 MyApp.view.ui.NewPerson 是一个包含属性网格和保存按钮的组件,因此将绑定(bind)两者的逻辑放在那里是有意义的:

Ext.define('MyApp.view.ui.NewPerson', {
    extend: 'Ext.window.Window',

   ...

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            dockedItems: [
                {
                    xtype: 'newpersontoolbar',
                    dock: 'bottom'
                }
            ],
            items: [
                {
                    xtype: 'newpersongrid'
                }
            ]
        });

        me.callParent(arguments);

        me.down('#savePersonButton').handler = function(button, e) {
          me.down('#newpersongrid').doSomething();
        }
    }

});

您需要分别向按钮和网格添加 itemId = 'savePersonButton'itemId = 'newpersongrid' 属性(因为它不是 id 它可以在组件的多个实例中使用,但每次的范围仅限于一个容器。

关于javascript - Extjs:访问窗口中链接的 Proprety Grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9385426/

相关文章:

javascript - 在旋转 Js 上更改变量的值

javascript - 如何配置 Kendo Upload 小部件以隐藏文件列表

javascript - 为什么我的 ASP.NET CORE React Redux 应用程序中的记录没有更新?

ExtJS GridPanel 行点击

javascript - 饼图未使用远程存储呈现(使用静态存储)

javascript - 如何为以下 Json 格式创建 JavaScript 逻辑

javascript - 获取包含换行符的文本值

extjs - 如何从 FontAwesome 更改图标的颜色

javascript - ExtJS 6 中可滚动 Accordion 的两个错误

javascript - 在 ExtJS 中传递参数