1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Answers
    1
    Vote Rating
    0
    rhomb is on a distinguished road

      0  

    Default Unanswered: General understanding of xtype vs Ext.create

    Unanswered: General understanding of xtype vs Ext.create


    Hello there,

    I realized a couple of times, that certain things in Sencha Touch don't seem to work as expected when using Ext.create, but work exactly as expected when just using the xtype.

    Example Setup:
    I have a Container with a button:
    Code:
    var productContainer = Ext.create('Ext.Container', {
        title: 'testContainer',
            layout: 'card',
        items: [
            {
                xtype: 'button',
                id: 'cartButton',
                text: 'Add to Cart',
                handler: function () {
                        console.log('test');
                    }
                }
             ],
    });
    The given container is in a tabPanel. The button handler doesn't work at all. I tried several things that came to my mind, like event delegation, addListener and so on. It just doesn't work.

    If I specify the Container like so:
    Code:
    var productContainer = {
        xtype: 'container',
            layout: 'card',
        title: 'heyhp',
        items: [
            {
                xtype: 'button',
                id: 'cartButton',
                text: 'Add to Cart',
                handler: function () {
                        console.log('test');
                    }
            },
        ],
    };
    Everything works fine, the only thing I changed is that I don't create the container over Ext.create but over an xtype.

    I noticed similar behavior a couple of times while messing with sencha touch, but after messing with this for at least 3-4 hours I really want to know why it didn't work with Ext.create?
    Most likely I'm missing some general knowledge I can't find on google, maybe somebody is so kind to enlighten me?

    Thanks
    rhomb

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Answers
    3540
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Ext.create is just like using the new keyword... it will create the class right then and there.

    Using xtype, this is what is called lazy-instantiation and the class will not be created until it is needed.

    So basically it's about when the class is to be actually created (instantiated).
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Answers
    1
    Vote Rating
    0
    rhomb is on a distinguished road

      0  

    Default


    Thanks Mitchell,
    thats what I thought, anyhow I don't understand what made the difference. It should've worked just like that.

    If you're saying that it shouldn't make any difference, I unfortunately still don't get why I didn't work in the first place.

    For now, I'll just let it be, and work with xtypes mostly.

    I appreciate the help though, thanks.

Thread Participants: 1