【问题标题】:ExtJS 4: Ext.grid.Panel constructor throwing exception when config and constructor configs are implementedExtJS 4:Ext.grid.Panel 构造函数在实现配置和构造函数配置时抛出异常
【发布时间】:2013-10-07 17:28:04
【问题描述】:

我正在尝试将名为“hideButton”的自定义参数传递给 Ext JS 4 中的网格视图构造函数。当我将“config”和“constructor”配置添加到我的网格视图。确实会调用警报消息。在我在警报对话框上单击“确定”后,将调用此异常。是什么导致了这个异常?

Ext.define('App.view.ExampleGrid', {
    extend: 'Ext.grid.Panel',
    xtype: 'view-grid-3',

    config: {   

        hideButton: false
    },

    constructor: function(cfg) {

        alert('called constructor');
        this.initConfig(cfg);
    },

...

我正在通过“xtype”配置使用延迟实例化从两个不同的其他组件实例化网格视图。这是需要通过调用构造函数在网格视图中隐藏按钮的组件。

items: [{
    region: 'center',
    xtype: 'view-tree-3',
    width: '40%'
}, {
    region: 'east',
    xtype: 'view-grid-3',
    store: 'GridStore',
    config: {
        hideButton: true
    },
    width: '60%'        
}]

【问题讨论】:

    标签: exception extjs extjs4 config


    【解决方案1】:

    假设您不能在 Ext JS 4.x 中使用 config 块。这暂时是 Touch 独有的功能。

    要在派生类中添加或覆盖配置选项,请将配置选项放在类声明主体中:

    Ext.define('App.view.ExampleGrid', {
        extend: 'Ext.grid.Panel',
    
        hideButton: false,
    
        ...
    });
    

    实例化时对实例配置做同样的事情:

    my grid = new App.view.ExampleGrid({
        hideButton: true // Overriding the default for this instance
    });
    

    【讨论】:

    • 啊。谢谢。如何在实例化之前将自定义值传递给视图?
    • 添加了几个例子,见上文。
    • 使用上面的代码后,我得到这个异常:'Uncaught ReferenceError: hideButton is not defined'
    • 没关系...我必须通过执行以下操作来实现自定义配置:“hidden: this.hideButton” .... 一切都很好!
    猜你喜欢
    • 2019-08-12
    • 2011-11-04
    • 2016-12-13
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 2018-05-21
    • 2012-04-15
    相关资源
    最近更新 更多