Results 1 to 2 of 2

Thread: Access to instances from callback

  1. #1
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    90
    Answers
    3

    Default Answered: Access to instances from callback

    Hi,
    I have the following situation within a controller:
    Code:
    //user is an instance of UserLogin (model)
    var user = Ext.create(model, this.getLoginform().getValues());
    
    
    user.save({
      success: function(record) {
                 console.log('Login success');
                 console.log(record.get('lastname'));
                 var mvp = Ext.getCmp('myviewport');
                 console.log(mvp);
               },...
    What I actually want, is to access an attribute that is part of the view MyViewport. I have also defined a reference to MyViewport (-> myviewport). What i get back from Ext.getCmp() is a pointer to the DOM object and not to the instance of MyViewport.
    Outside of the callback I can access the sttribute via this.getMyviewport().attribute.
    Maybe i have a fundamental misunderstanding or there is any other mistake.

    Any comment or hint is welcome.

  2. you can set the callback scope "where to execute your callback function"

    if your user.save is inside a controller method then just pass "this" as scope
    Code:
    user.save({   
           success: function(record)  {                  
               console.log('Login success');              
               console.log(record.get('lastname'));              
               var mvp = Ext.getCmp('myviewport');              console.log(mvp);            
               },...
            scope : this
    });
    now inside the callback function "this" will point to the controller

  3. #2
    Sencha User
    Join Date
    Dec 2011
    Posts
    224
    Answers
    13

    Default

    you can set the callback scope "where to execute your callback function"

    if your user.save is inside a controller method then just pass "this" as scope
    Code:
    user.save({   
           success: function(record)  {                  
               console.log('Login success');              
               console.log(record.get('lastname'));              
               var mvp = Ext.getCmp('myviewport');              console.log(mvp);            
               },...
            scope : this
    });
    now inside the callback function "this" will point to the controller

Posting Permissions

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