2012-11-14 20 views
1
當我上面的代碼運行
this.getSecondPanel = function(argPanel, argID) 
{ 
    Ext.Ajax.request({ 
     url  : 'myActionURL', 
     params : {id: argID}, 
     success : function(response) 
     { 
      var resData = Ext.util.JSON.decode(response.responseText); 
      var totalCount = resData.totalCount; 

      argPanel.items.insert(0, this.getTotalCountPanel(totalCount)); 
     }, 
     failure : function(response) 
     { 
      Ext.Msg.alert('Error: ', response); 
     } 
    }); 
}; 

this.getTotalCountPanel = function(argCounter) 
{ 
    return new Ext.Panel({ 
     title : 'Summary Panel', 
     html : '<table class="bgrGREYlight" width="100%" style="padding:5">' + 
        '<tbody>' + 
         '<tr>' + 
          '<th align="left" width="20%" class="tableTEXT2">' + Total Count + '</th>' + 
          '<td width="80%" align="left" class="tableTEXT">' + argCounter + '</td>' + 
         '</tr>' + 
        '</tbody>' + 
        '</table>' 
    }); 
}; 

,它給如何在ExtJS中將範圍作爲參數傳遞?

TypeError: this.getTotalCountPanel is not a function

錯誤。我想這是一個範圍問題。我該如何解決這個錯誤?

回答

2

是的,你可以在請求方法選項對象中設置scope: thishttp://docs.sencha.com/ext-js/4-1/#!/api/Ext.Ajax-method-request

this.getSecondPanel = function(argPanel, argID) 
{ 
    Ext.Ajax.request({ 
     scope:this, //<----- scope set to current context 
     url  : 'myActionURL', 
     params : {id: argID}, 
     success : function(response) 
     { 
      var resData = Ext.util.JSON.decode(response.responseText); 
      var totalCount = resData.totalCount; 

      argPanel.items.insert(0, this.getTotalCountPanel(totalCount)); 
     }, 
     failure : function(response) 
     { 
      Ext.Msg.alert('Error: ', response); 
     } 
    }); 
}; 
+0

thx很多,它的工作原理! – vtokmak

相關問題