Hybrid View

  1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    385
    Vote Rating
    4
    gkatz is on a distinguished road

      0  

    Default refs / control MVC problem

    refs / control MVC problem


    Hi;
    I have an MVC ST2.1 app with a single main controller as follows:
    Code:
            refs: {
            homeBtn:'#titlebarHomeBtn',
            },
            control: {
                homeBtn: {
                    tap: 'homeBtnTapped'
                }        
            }
            .....
            homeBtnTapped: function(btn,ev){...}
    my main view is a simple container with a card layout. card 0 has a single button (lets call it 'go'). card 1 does not yet exist...
    when pressing the 'go' button on card 0 the controller adds a view (card 1) with the home button as follows:
    Code:
    Ext.define('DynView', {
        extend: 'Ext.Container',
        requires: [ ...  ],
        config: {
            layout: 'fit',
            items:[{
                    xtype: 'titlebar',
                    docked: 'top',
                    items: [
                        {
                            id: 'titlebarHomeBtn',
                            iconCls: 'home',
                            iconMask: true,
                            align: 'left'
                        }
                    ]
    
    
                }
            ]
        }
    });
    now, it when pressing the home button the contoller's homeBtnTapped function is called and its code switches to card 0 and destroys card 1.
    Now for the second time, if I click the 'go' button, card 1 is dynamically created but the home button does not work. as if the refs/control only bonded once and cannot bind again.
    is this a know behavior?
    thanks.

  2. #2
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    497
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      0  

    Default


    If you are using control on a controller to handle events, you have to be very careful that only one component will ever match the selector at any one time.

    I imagine this is probably causing the problem here... when the DynView is removed after being shown for the first time, are you destroying it? Even if it's not visible, and still lingering in the memory in the background, it will still match the selector. So when the second DynView comes in, both potentially match, and Sencha Touch doesn't handle that well.

    I've found myself using control {} less and less over time to avoid situations like this. Which is a shame because if it could match multiple items it would be much more useful. Maybe it can, and I don't know how, in which case I'm all ears!

  3. #3
    Sencha User
    Join Date
    Nov 2010
    Posts
    385
    Vote Rating
    4
    gkatz is on a distinguished road

      0  

    Default


    thanks for your answer.
    I destroy the DynView way before I created a new one... and it still does not work.
    I would post the whole code but its very hard for me to reduce my app to something that is postable...
    any other suggestions?

  4. #4
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Vote Rating
    6
    cyee is on a distinguished road

      0  

    Default


    Maybe initConfig() will be useful?

  5. #5
    Sencha User
    Join Date
    Nov 2010
    Posts
    385
    Vote Rating
    4
    gkatz is on a distinguished road

      0  

    Default


    cyee what do you mean?

  6. #6
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Vote Rating
    6
    cyee is on a distinguished road

      0  

    Default


    I'm not sure

    There's an initConfig() method in the controller that re-applies the configuration object. However, I'm not entirely sure that it will do what you want.