2013-03-02 40 views
1

我在Extjs4中工作,我陷入了一點,我想調用另一個函數內部的函數。在extjs4中如何在另一個函數裏面調用函數?

這裏我要在成功函數中調用hideLoginWindow()函數。

如何在成功函數中調用hideLoginWindow()函數。 這裏是我的控制文件中的代碼

Ext.define('Am.controller.sn.UserController', 
     { 

      extend:'Ext.app.Controller', 
      stores:['sn.UserStore','sn.SecurityquestionStore'], 
      models:['sn.UserModel','sn.SecurityquestionModel'], 
      views:['sn.user.Login','sn.user.Registration','sn.user.ForgetMyKey','sn.user.SecurityQuestion','sn.user.KpLogin'], 


      init:function() 
      { 
       console.log('Initialized Users! This happens before the Application launch function is called'); 
       this.control(
       { 
        'Login button[action=loginAction]': 
        { 
         click:this.authenticateUser 
        }, 
        'Login button[action=registerAction]': 
        { 
         click:this.registerUser 
        }, 
        'KpLogin button[action=loginAction]': 
        { 
         click:this.authenticateUser 
        } 
       });//end of this.control  
      },//end of init function  
    authenticateUser:function(button) 
    { 
     ***// this function is called 
     this.temp();*** 

     var email=this.getUserName().getValue(); 
     var password=this.getPassword().getValue(); 
     console.log("Email"+email); 
     console.log("Password"+password); 
     var check = Ext.ModelManager.create(
     { 
      primaryEmail:email, 
      password: password, 
     }, 'Am.model.sn.UserModel'); 
     check.save(
     { 
      success: function(record, operation) 
      { 

       if(operation.request.scope.reader.jsonData["id"]==1) 
       { 
        // Code for geting component 
        alert("you are logged in successfully"); 

        **//this function is not called 
        this.hideLoginWindow(); // I tried also hideLoginWindow();** 

       }//end of if statement 


      },//End of success function 
      failure: function(record, operation) 
      { 
       console.log("Inside failure function"); 

      },//End of failure function 

     });// End of check save function 
     console.log("outside authenticated function"); 

    },//end of authenticate user function 


    //***************************Reusable functions******************** 
    // this function get called 
    temp:function() 
    { 
     console.log("Temp function called"); 
    }, 
    //this function is not get called 
    hideLoginWindow:function() 
    { 
     var obj=Ext.ComponentQuery.query('#loginId'); 
     console.log("Object name = "+obj[0].id); 
     obj[0].hide(); 
    } 
});// End of login controller 

當我運行這段代碼,我得到的錯誤是

遺漏的類型錯誤:對象的翻譯:有沒有一種方法「hideLoginWindow」

我怎麼能在成功函數裏調用hideLoginWindow()函數。

回答

1

您需要將設置保存回調的範圍:

check.save({ 
    scope: this, 
    success: function() {} 
}); 
+0

它的工作....非常感謝.. – 2013-03-02 11:23:18

1

你要問自己,什麼是this在你的方法調用的點?由於該調用位於另一個函數中,因此該作用域現在位於該函數內,而不在您的方法所在的外部對象中。

做的最好的事情是設置check.save方法調用之前的範圍...

check.save({ 
    scope: this, 
    //... 
}); 

,當你進入你的函數調用這將保留外部對象的範圍

+0

它works.Thanks給予更多的信息。 – 2013-03-02 11:23:49

相關問題