-
27 Feb 2012 12:57 PM #1
Unanswered: How can I access the main application from controllers MVC
Unanswered: How can I access the main application from controllers MVC
I want to fire and receive events (application events) between two controllers. Please can anyone let me know if they can get this.Application.on working ...for me this is undefined.
Please also make sure the version is 2-rc thanks
-
27 Feb 2012 1:37 PM #2
I am using this.getApplication().addListener() and this.getApplication().fireAction() or this.getApplication().fireEvent()
-
27 Feb 2012 2:01 PM #3
Controller to Controller MVC SenchaTouch
Controller to Controller MVC SenchaTouch
Thanks that little nugget was eluding me today !! And couldn't find it anywhere in examples. My code
Send Application Event within sening controller function where target gives me the scope or object that is the controller
Receive Application EventCode:target.getApplication().fireEvent('buyorsell', amt);
And the reason why this is favoured is as it is an event it can be subscribed to or listened to by more than one entity and for example the listeneing class in this case can be removed without an error in the program. If we directly targeted a function in a different controller we have created a more solid link that while easy to spot is not as preffered. AFAIKCode:Ext.define('App.controller.Trade', { extend: 'Ext.app.Controller', config: { refs:{ }, control: { } }, launch:function(){ this.getApplication().on({ buyorsell: this.buyMethod, scope: this });
-
24 Mar 2012 6:13 PM #4
What exactly the target should be?? i.e. How do you exactly reference another controller? I tried already about 2 dozen combinations. I am on official commercial version of 2.0. I always get error like following:Code:target.getApplication().fireEvent('buyorsell', amt);
Code:TypeError: 'undefined' is not a function (evaluating 'this.getController('WP.controller.ChartController')')
-
24 Mar 2012 6:30 PM #5
And of course 2 days of frustration ends in 5 minutes after one writes the question in the forum. What I have found was the same old scoping issue. I called fireEvent from a callback(!) using 'this.' Of course it didn't work because it couldn't find anything it was looking for within the callback itself. So what worked is:
Code:var me = this; chartstore.load({ callback: function(records, operation, success) { me.getApplication().fireEvent('chartloaded'); } });
-
26 Mar 2012 5:17 AM #6
I had a lot of frustration too ! I'm sorry not to have got back to you to help but I'm not working for sencha myself. I am liek you trying to get things to work. But javascript scope is always a tricky one.


Reply With Quote