Results 1 to 6 of 6

Thread: extending of parent class doesn't work

  1. #1
    Sencha User
    Join Date
    Mar 2013
    Posts
    4
    Vote Rating
    0
      0  

    Default Answered: extending of parent class doesn't work

    Hi, could someone of you please take a look at this both peaces of code, and tell me why my childClass doesn't work. It doesn't show my another items (someAnotherItem,someAnotherItem2) , instead there are always called parent items (someItem,someItem2), when i try to use myChildClass.
    I can see console.log('yuhu')


    parent
    PHP Code:
    Ext4.define('MyParentClass', {
        
    extend 'Ext4.Panel',
        
    alias 'widget.myParentClass',

        
    /**
         * Initialize  configuration.
         */
        
    initComponent : function() {
            
    Ext4.apply(this, {
                
    layout'border',
                
    items: [{
                    
    xtype'someItem',
                    
    region'north',
                    
    layout'fit',
                    
    collapsibletrue,
                    
    splittrue
                
    },{
                    
    xtype'someItem2',
                    
    layout'fit',
                    
    region'center'
                
    }]
            });

            
    this.callParent(arguments);
            
    this.on('added',this.initListenersthis);
        },
         
    /**
         * initialize events
         */
        
    initListeners: function(componentcontainer){
            
    /*some events*/
        
    }

    }); 
    and my child class
    PHP Code:
    Ext4.define('MyChildClass', {
        
    extend 'MyParentClass',
        
    alias 'widget.myChildClass',

        
    /**
         * Initialize  configuration.
         */
        
    initComponent : function() {
            
    Ext4.apply(this, {
                
    items: [{
                    
    xtype'someAnotherItem',
                    
    titlethis.i18n.title,
                    
    collapsiblefalse
                
    },{
                    
    xtype'someAnotherItem2'
                
    }]
            });
            
    console.log('yuhu');
            
    this.callParent(arguments);
        }

    }); 
    Thanks for your help
    regards
    Kondorek

  2. I've explained the template method approach here:

    http://skirtlesden.com/articles/conf...-the-prototype

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    The apply method just copies properties from one object to another. Your child class sets items on this and then calls callParent, which will call the parent class's initComponent. That will change the value of items on this.

    You could use applyIf instead, or add a template method that returns the items config rather than setting it directly in both classes.

  4. #3
    Sencha User
    Join Date
    Mar 2013
    Posts
    4
    Vote Rating
    0
      0  

    Default

    thank you @skirtle applyIf seams doesn't work properly in my case.
    I try to use some template but i'm affraid i've to use the worst method and create exactly copy of my parent class. It's not pretty but it 100% works

  5. #4
    Sencha User
    Join Date
    Mar 2013
    Posts
    4
    Vote Rating
    0
      0  

    Default

    thanks skirtle, but applyIf seams not to work
    i try to use templates but in worst case I'll be forced to repeat the code

  6. #5
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      1  

    Default

    I've explained the template method approach here:

    http://skirtlesden.com/articles/conf...-the-prototype

  7. #6
    Sencha User
    Join Date
    Mar 2013
    Posts
    4
    Vote Rating
    0
      0  

    Default

    that looks great, thanks skirtle

Posting Permissions

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