Results 1 to 2 of 2

Thread: pass a function reference

  1. #1
    Touch Premium Member BostonMerlin's Avatar
    Join Date
    Aug 2010
    Location
    Boston
    Posts
    548
    Answers
    22
    Vote Rating
    44
      0  

    Default Unanswered: pass a function reference

    I've created a controller function that loads data from the server. When the ajax call is complete, I want to call another function that is not known at design time. I assume there is a way to pass a callbackFunction reference into the loadData function to be called once complete. Depending on the state of my app, I may want to call any number of functions but I don't want to hardcode anything in the ajax success event other than calling the passed in function reference.

    Best practice, thoughts, direction?

    Thanks in advance,
    John

  2. #2
    Touch Premium Member BostonMerlin's Avatar
    Join Date
    Aug 2010
    Location
    Boston
    Posts
    548
    Answers
    22
    Vote Rating
    44
      0  

    Default

    I've gotten this far but am dealing with a scoping issue.

    Pseudocode... ignore syntax specifics:

    In controller [Main] I do something like this:

    Code:
    var callBack = this.ShowView;
    this.getApplication().getController('Project').LoadProjects(callBack);
    In controller [Project] I do something like this:

    Code:
    LoadProjects: function(callBackF) {
    
    store.load({
       callback: function(records, operation, success){
             callBackF();
    }
    Back in controller [Main] the callback function is executed:

    Code:
    ShowView: function(){
        this.getNavViewRef().show();  //-this errors out
    }

    When the store load is complete, the callBackF() function is called which happens to live back in the [Main] controller. Within that callback function, code errors on the call to a controller reference on that controller this.getNavViewRef();.

    I suspect I need to do something with scope but not sure what specifically and where to apply. Do I need to pass 'this' from [Main] controller to [Project] controller and back to [Main] ? Seems awfully inefficient.

    Thoughts?

    Thanks again in advance,
    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •