1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    255
    Vote Rating
    2
    Answers
    6
    landed is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha User
    Join Date
    Nov 2010
    Posts
    8
    Vote Rating
    0
    mslosarek is on a distinguished road

      0  

    Default


    I am using this.getApplication().addListener() and this.getApplication().fireAction() or this.getApplication().fireEvent()

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    255
    Vote Rating
    2
    Answers
    6
    landed is on a distinguished road

      0  

    Cool 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
    Code:
    target.getApplication().fireEvent('buyorsell', amt);
    Receive Application Event
    Code:
    Ext.define('App.controller.Trade', {  extend: 'Ext.app.Controller',
      
        config: {
    	   
    	    refs:{
    
    
            },
    		control: {
    
    
    		}
    	   
    	   },
      
      launch:function(){
      
    	this.getApplication().on({
            buyorsell: this.buyMethod,
            scope: this
        });
    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. AFAIK

  4. #4
    Sencha User
    Join Date
    Dec 2011
    Location
    Sacramento, California
    Posts
    75
    Vote Rating
    9
    gypsie will become famous soon enough

      0  

    Default


    Code:
    target.getApplication().fireEvent('buyorsell', amt);
    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:
    TypeError: 'undefined' is not a function (evaluating 'this.getController('WP.controller.ChartController')')

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Location
    Sacramento, California
    Posts
    75
    Vote Rating
    9
    gypsie will become famous soon enough

      0  

    Default


    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');
            }
    });

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    255
    Vote Rating
    2
    Answers
    6
    landed is on a distinguished road

      0  

    Thumbs up


    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.

Thread Participants: 2