1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    14
    Vote Rating
    0
    lotrmj is on a distinguished road

      0  

    Default MVC. Why do we use initComponent() method in View???

    MVC. Why do we use initComponent() method in View???


    Hi, look at these:
    Code:
    Ext.define('mv.view.some', {
        extend: 'Ext.Panel',
        alias: 'widget.some',
    
        title: 'Some',
    
        initComponent: function() {
            this.items = [
                {
                    xtype: 'form',
                    items: [
                        {
                            xtype: 'textfield',
                            name : 'name',
                            fieldLabel: 'Name'
                        },
                        {
                            xtype: 'textfield',
                            name : 'email',
                            fieldLabel: 'Email'
                        }
                    ]
                }
            ];
    
            this.callParent(arguments);
        }
    });
    Code:
    Ext.define('mv.view.some', {
        extend: 'Ext.Panel',
        alias: 'widget.some',
    
        title: 'Some',
    
            items: [
                {
                    xtype: 'form',
                    items: [
                        {
                            xtype: 'textfield',
                            name : 'name',
                            fieldLabel: 'Name'
                        },
                        {
                            xtype: 'textfield',
                            name : 'email',
                            fieldLabel: 'Email'
                        }
                    ]
                }
            ]
    });
    Result appears to be the same (at least visually). So why you use initComponent()? What is advantage of this?

  2. #2
    Ext JS Premium Member westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    894
    Vote Rating
    39
    westy is a jewel in the rough westy is a jewel in the rough westy is a jewel in the rough

      0  

    Default


    Items defined inline are processed at class definition time, so you have no state, or config.

    You define your items in initComponent in case you want to perform some processing to determine what controls to include, exclude, or initialise them differently. Or perhaps to control the form panels content from the config object that was passed to the constructor.

    I can think of many reasons why you'd want to do this, and surely you can too!
    Product Architect
    Altus Ltd.

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi