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>'
    });
};

当我运行上面的代码时,它给出了

TypeError:this.getTotalCountPanel 不是函数

错误。我想这是一个范围问题。我该如何解决这个错误?

4

1 回答 1

2

是的,您可以scope: this在请求方法选项对象中进行设置。 http://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);
        }
    }); 
};
于 2012-11-14T22:24:20.087 回答