• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

[ANSWERED] callback for getController ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [ANSWERED] callback for getController ?

    Is there a way to put a callback on a getController so that the next line of code in the function doesn't execute until the call to the other controller returns a value?

    for example if you want to do something like this:

    var myVar = this.getContoller('myControler2').onSomeFunction(a , b);

    if(myVar === "returned from getController value"){
    //do something
    }else{
    //do something else
    }

  • #2
    It would depend on what's going on inside "onSomeFunction." Is there asynchronous activity going on in there like an Ajax call? If not it should work the way you want straight away. If there is an Ajax call in there then you could pass a callback function as an additional parm.

    Comment


    • #3
      welcome back! hope you had a good one!

      Yes, there is an Ajax call in onSomeFunction. I couldn't figure out how to code the callback on the getController.

      Comment


      • #4
        Just create a separate function that handles what to do when the onSomeFunction is finished and then on the callback within onSomeFunction you can just fire an event that would call your logic.

        Comment


        • #5
          I understand what you said, but can't translate that to code.. I need a visual.. i.e.

          var myVar = this.getContoller('myControler2').onSomeFunction(a , b).callback(????)

          i don't really need to do anything but wait to get a value into myVar before the next line executes

          Comment


          • #6
            Are you getting an error or just no action?

            In the success property/function of the ajax, that is the callback.

            If that is not in your controller, you could fire an event your controller listens to.

            I assume you are just typing pseudo code here, but maybe you have a typo in myControler2?

            Comment


            • #7
              Oh... then that doesn't really get me anything... I was trying to avoid doing some of the code inside the success function..
              I was hoping there was something like what you can do for loading stores, such as

              var store = this.getStore('Mystore');
              store.load({
              callback: function(){
              //do whatever
              }
              });

              Comment


              • #8
                Mike,

                Here is a quick example of passing a callback to your some function..

                onSomeFunction
                Code:
                    onSomeFunction : function(callback,scope){
                        var me        = this,
                            scope     = scope || this,
                            callback  = callback || null;
                
                        //make ajax call
                        //
                        Ext.Ajax.request({
                            url     : '/valence/yourpgm.pgm',
                            params  : {
                                action : 'doLogic'
                            },
                            scope   : me,
                            success : function(){
                                //if callback was passed call it
                                //
                                if (callback) {
                                    if (typeof this.callback === 'function'){
                                        Ext.callback(callback,scope);
                                    } else {
                                        Ext.callback(eval(callback),scope);
                                    }
                                }
                            }
                        });
                    },
                
                    onCallback : function(){
                        console.log('finished');
                    },
                
                    request : function(){
                        var me = this;
                        me.onSomeFunction(me.onCallBack, this);
                    }
                Last edited by Johnny Major; 07-01-2014, 09:57 AM.

                Comment


                • #9
                  I knew I could count on JohnnyFootball!!.. I thought Ext.callback was they key. I was playing around with it but needed this hint.. THANKS!!! u da man!

                  Comment

                  Working...
                  X