用EXT.EXTEND定义了一个对象,这个对象要在页面载入时才实例化,问题是在写js的时候还写了一个方法,需要访问这个对象的属性和方法,如何解决呢?
而不用Ext.extend定义对象,而直接用new方法实现化对象,是可以访问对象的属性和方法的!

解决方案 »

  1.   

    extend继承我用的不多,而且我觉得ext本身的结构良好,擅自用extend不知道会出什么问题。
    lz说的情况我测试的时候也发现了。九拿ext包下面的examples->grid->array-grid.html作例子,
    并且用Ext给的示例方法来继承Ext.grid.GridPanel,    MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
            constructor: function(config) {
                // Your preprocessing here
             MyGridPanel.superclass.constructor.apply(this, arguments);
                // Your postprocessing here
                //如果象西面这样在这里通过原型覆盖方法可行,因此我觉得,如果实在要用继承,在这里写最合适。
                //MyGridPanel.prototype.toString = function(){return "This is subclass method."}
            },
         //发现这里写一个覆盖父类的方法无效。
            toString: function() {
                return "This is subclass method toString."
            }
         //但是我在这里写一个非父类的方法是可以的。
             ff: function() {
                return "This is subclass method ff."
            }
        });    var grid = new MyGridPanel({
            store: store,
            columns: [
                {id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
                {header: "Price", width: 75, sortable: true, renderer: 'usMoney', dataIndex: 'price'},
                {header: "Change", width: 75, sortable: true, renderer: change, dataIndex: 'change'},
                {header: "% Change", width: 75, sortable: true, renderer: pctChange, dataIndex: 'pctChange'},
                {header: "Last Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
            ],
            stripeRows: true,
            autoExpandColumn: 'company',
            height:350,
            width:600,
            title:'Array Grid'
        });
        alert(grid.ff());
        //alert(grid.toString());