Results 1 to 6 of 6

Thread: Params to constructor/init of an extended class?

  1. #1
    Sencha User jvolt's Avatar
    Join Date
    Jan 2008
    Posts
    44
    Vote Rating
    0
      0  

    Default Params to constructor/init of an extended class?

    How to pass params to a Extended class?
    i.e

    Code:
    MyWindow = Ext.extend(Ext.Window, {
        title: 'My Window ' + param1,
        initComponent: function() {
            this.items = [
    			{
    				xtype: 'panel',
    				html: param2
    			}
        }
    });
    Because i need use that params when create a new window...

  2. #2
    Sencha User
    Join Date
    Sep 2009
    Location
    Calgary, Alberta, Canada
    Posts
    638
    Vote Rating
    2
      0  

    Default

    Code:
    constructor: function(config) {
        config = config || {};
        // Your config are the parameters that you pass.
        Ext.apply(this, config);
        MyWindow.superclass.constructor.call(this);
    }

  3. #3
    Sencha User jvolt's Avatar
    Join Date
    Jan 2008
    Posts
    44
    Vote Rating
    0
      0  

    Default

    Thanks very much CrazyEnigma =D

    I don't understand what "config = config || {};" does tho

  4. #4
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,676
    Vote Rating
    9
      0  

    Default

    config is config or (if not exists) an empty object. Such expression is needed so config isn't undefined.

    It's a shorter form of

    Code:
    config = config !== 'undefined' ? config : {};
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  5. #5
    Sencha User jvolt's Avatar
    Join Date
    Jan 2008
    Posts
    44
    Vote Rating
    0
      0  

    Default

    Oh Thanks steffenk =D

    Very useful!

  6. #6
    Sencha User jvolt's Avatar
    Join Date
    Jan 2008
    Posts
    44
    Vote Rating
    0
      0  

    Default

    [SOLVED]
    Hello again guys,

    I've tried that but got an error.

    Code:
    adicionarBonus = Ext.extend(adicionarBonusUi, {
    	constructor: function(cfg) {
    		cfg = cfg || {};		
    		adicionarBonus.superclass.constructor.call(this, Ext.apply(this, cfg));
    	},
        initComponent: function() {
            adicionarBonus.superclass.initComponent.call(this);
        }
    });
    Firebug show the error:
    h.directCfg is undefined =(

    That is an extended window with a grid (the grid uses a directfn, i will do that to populate the grid using a param from the constructor)


    SOLVED. The problem was on Ext Designer Expor, if you has got same problem look here:

    http://www.extjs.com/forum/showthrea...ight=DirectCfg
    Last edited by jvolt; 30 May 2010 at 6:11 PM. Reason: SOLVED

Similar Threads

  1. Passing parameters to extended class constructor
    By Greendrake in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 16 Dec 2009, 8:04 AM
  2. change extended Metagrid url and store params
    By AndrewY in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 29 Oct 2009, 12:30 AM
  3. Extended Class: Is Not A Constructor
    By Chris55 in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 1 Oct 2009, 11:57 AM
  4. getForm() From an Extended Class
    By learningExt in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 1 Jul 2008, 6:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •