开发者

Why does this Ext.grid.Panel crash?

This crashes:

var grdMakes = Ext.extend(Ext.grid.Panel, {
  constructor: function(paConfig) {
  }
}

This does not:

var grdMakes = Ext.extend(Ext.grid.Panel, {
}

The crash is:

Uncaught TypeError: Cannot read property 'added' of undefined

Why does adding a constructor cause it to crash? I can do it with other objects like:

var pnlMakesMaint = Ext.extend(Ext.Panel, {
    constructor: function(paConfig) {
    }
}  // just fine

EDIT

To clarify what I want to do is that I want to be able to instantiate an object with the option to override the defaults.

var g = new grdMakes({});  // defaults used

var g = new grdMakes({renderTo: Ext.getBody()}); // renderTo overridden

This is working for everything except the Ext.grid.Panel

Also, I'm using ExtJS 4

SOLUTION

Turns out, extend is deprecated in ExtJS 4. So I used this and it works:

Ext.define('grdMakes', {
     extend: 'Ext.grid.Panel',

     constructor: function(paConfig) {
        var paConfig = Ext.apply(paConfig || {}, {
 开发者_Go百科          columns:   !paConfig.columns ? [{
              header: 'Makes',
              dataIndex: 'make'
           }, {
              header: 'Description',
              dataIndex: 'description'
           }]: paConfig.columns,
           height:     !paConfig.height ? 400 : paConfig.height,
           renderTo:   !paConfig.renderTo ? Ext.getBody() : paConfig.renderTo,
           store:      !paConfig.store ? stoMakes : paConfig.store,
           title:      !paConfig.title ? 'Makes' : paConfig.title,
           width:      !paConfig.width ? 600 : paConfig.width

        });

        grdMakes.superclass.constructor.call(this, paConfig);
     }
}


Ok.But your code seems like ExtJS3.Because Ext.extend is depreceated in ExtJS4 version.Instead of extend you can use define.For reference you can check the following url:

http://docs.sencha.com/ext-js/4-0/#/api/Ext-method-extend

Afaik,for overriding default options,this is not the perfect way.You need to use Ext.override.

For example:

Ext.override(Ext.grid.Panel,{
   lockable : true
});

Like above you have to override the default options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜