Hybrid View
-
30 Jan 2013 6:33 AM #1
refs / control MVC problem
refs / control MVC problem
Hi;
I have an MVC ST2.1 app with a single main controller as follows:
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...Code:refs: { homeBtn:'#titlebarHomeBtn', }, control: { homeBtn: { tap: 'homeBtnTapped' } } ..... homeBtnTapped: function(btn,ev){...}
when pressing the 'go' button on card 0 the controller adds a view (card 1) with the home button as follows:
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.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 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.
-
30 Jan 2013 8:26 AM #2
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!
-
30 Jan 2013 8:30 AM #3
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?
-
30 Jan 2013 9:07 AM #4
Maybe initConfig() will be useful?
-
30 Jan 2013 9:10 AM #5
-
30 Jan 2013 11:10 AM #6
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.


Reply With Quote