2014-09-22 36 views
0

我嘗試創建一個使用PHP與ExtJS的登錄,但我堅持了這個問題...建築LOGIN不是一個函數

TypeError: this.getView is not a function 


this.getView().destroy(); 

這裏是我的代碼....

我不知道爲什麼它可能是錯誤,我只是嘗試按照煎茶文檔

buttons: [{ 
      text: 'Login', 
      formBind: true, 

     listeners: { 
      click: function() { 
             var form = Ext.getCmp('login').getForm(); 

             if(form.isValid()) { 
               form.submit({ 
                 url : 'data/login.php', 
                 method : 'POST',              

                  success:function(){ 
                  this.getView().destroy(); 
                  Ext.widget('app-main'); 
                   }, 
                  failure: function() { 
                     obj = Ext.util.JSON.decode(response.responseText); 
                     Ext.Msg.alert('Login Failed!', obj.errors); 
                  } 
               }); 
             } 
           }    
     } 
     }] 

回答

2

您是否嘗試過console.log(this)教程?我猜不是...

this總是依賴於上下文。這裏的上下文不是視圖,但是,如果我沒有弄錯,Ext.Ajax.request,其中的success函數試圖破壞視圖。

這就是爲什麼我在我的代碼使用該避免無論它是不是完全明顯甚至是外行的讀者,我這方面的

編輯:由於代碼看起來不好的評論,我在這裏添加它。 答案按原來的分機來源是

click: function() { 
    var me = this; 
    var form = Ext.getCmp('login').getForm(); 

    if(form.isValid()) { 
     form.submit({ 
      url : 'data/login.php', 
      method : 'POST', 

      success:function(){ 
       me.getView().destroy(); 
       Ext.widget('app-main'); 
      }, 
      failure: function() { 
       obj = Ext.util.JSON.decode(response.responseText); 
       Ext.Msg.alert('Login Failed!', obj.errors); 
      } 
     }); 
    } 
} 

而我個人會用

click: function(btn) { 
    var form = Ext.getCmp('login').getForm(); 

    if(form.isValid()) { 
     form.submit({ 
      url : 'data/login.php', 
      method : 'POST', 

      success:function(){ 
       btn.up('window').hide(); 
       Ext.widget('app-main'); 
      }, 
      failure: function() { 
       obj = Ext.util.JSON.decode(response.responseText); 
       Ext.Msg.alert('Login Failed!', obj.errors); 
      } 
     }); 
    } 
} 
+0

嗨,先生你有什麼想法要解決或如何實現我想要做即時通訊相當卡住了創建一個登錄和IM只是在extjs – itsmecidz 2014-09-22 09:38:10

+0

begineer我在原來的帖子中添加了一些代碼。 – Alexander 2014-09-22 09:44:45

+0

謝謝先生!我嘗試了第一個,但我沒有工作,然後我嘗試第二個,它的工作原理!感謝你的時間 – itsmecidz 2014-09-22 10:01:52