runjia1987 2010-04-27 18:58
浏览 306
已采纳

继承Ext.panel的子类实例化出错:this.add() is not a function

[code="java"]
Ext.namespace("SXP.Ext");
SXP.Ext.WelcomePage = Ext.extend(Ext.Panel, {
id : 'desktop_index',
title : '首 页',
closable : false,
autoScroll : true,
layout : "fit",
border : false,
getAjaxRequest : function() {
Ext.Ajax.request({
url : 'util?cmd=loadOnStart',
success : function(response) {
this.respText = Ext.decode(response.responseText);
this.store1 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.news
});
this.store2 = new Ext.data.SimpleStore({
fields : ['column', 'value'],
data : this.respText.statist
});
this.store3 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.notice
});
this.store4 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.rule
});
this.store5 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.mannual
});
this.store6 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.faq
});
},
failure : function() {
Ext.MessageBox.show({
title : '系统提示',
msg : '加载首页数据时出错了!',
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.WARNING
});
}
});
},
fresh : function() {
if (this.store1 != null) {
this.store1.removeAll();
this.store2.removeAll();
this.store3.removeAll();
this.store4.removeAll();
this.store5.removeAll();
this.store6.removeAll();
}
this.getAjaxRequest();
},
createWin : function(width, height, type) {
var desc = "";
if (type == 'news')
desc = "最新新闻报道";
else if (type = 'rule')
desc = "系统运行规范";
else if (type == 'notice')
desc = "系统动态通知";
else if (type == 'mannual')
desc = "系统操作说明书";
else if (type == 'faq')
desc = "系统第一次使用必读";
var win = new Ext.Window({
width : width,
height : height,
title : desc,
modal : true,
resizable : false,
items : [{
xtype : 'tabpanel',
id : 'read_detail',
autoLoad : {
url : "",
nocache : false,
scripts : true
}
}]
});
return win;
},
buildComponent: function(){
Ext.Ajax.request({
url : 'util?cmd=loadOnStart',
success : function(response) {

Ext.MessageBox.hide();
this.respText = Ext.decode(response.responseText);
this.store1 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.news
});
this.store2 = new Ext.data.SimpleStore({
fields : ['column', 'value'],
data : this.respText.statist
});
this.store3 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.notice
});
this.store4 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.rule
});
this.store5 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.mannual
});
this.store6 = new Ext.data.SimpleStore({
fields : ['type', 'id', 'title', 'date'],
data : this.respText.faq
});
this.containerPanel = new Ext.Panel({
border : false,
layout : 'table',
bodyStyle : 'margin:0;padding:0',// background:#DFE8F6;
layoutConfig : {
columns : 3
},
defaults : {
frame : false
},
tbar : new Ext.Toolbar({
id : 'tbar_welcome',
items : ['-', {
xtype : 'button',
text : '刷新本页',
iconCls : 'refresh',
handler : this.fresh,
scope : this
}, '-']
}),
items : [{
columnWidth : .35,
title : '最新新闻报道',
hideBorders : true,
hideHeaders : true,
collapsible : true,
style : 'padding:5px',
height : 300,
frame : false,
viewConfig : {
forceFit : true
},
loadMask : true,
items : new Ext.grid.GridPanel({
border : false,
store : this.store1,
columns : [{
width : '75%',
dataIndex : 'title',
renderer : this.renderTitle
}, {
width : '25%',
dataIndex : 'date'
}]
})
}, {
columnWidth : .30,
title : '系统运行统计',
style : 'padding:5px;paddingLeft:0',
height : 300,
collapsible : true,
viewConfig : {
forceFit : true
},
hideHeaders : true,
loadMask : true,
frame : false,
items : new Ext.grid.GridPanel({
border : false,
store : this.store2,
columns : [{
width : '60%',
dataIndex : 'column'
}, {
width : '40%',
dataIndex : 'value'
}]
})
}, {
columnWidth : .35,
title : '系统动态通知',
html : '

More>>  

',
style : 'padding:5px;paddingLeft:0',
height : 300,
collapsible : true,
viewConfig : {
forceFit : true
},
hideHeaders : true,
loadMask : true,
frame : false,
items : new Ext.grid.GridPanel({
border : false,
store : this.store3,
columns : [{
width : '75%',
dataIndex : 'title',
renderer : this.renderTitle
}, {
width : '25%',
dataIndex : 'date'
}]
})
}, {
columnWidth : .35,
title : '系统运行规范',
hideBorders : true,
hideHeaders : true,
collapsible : true,
shadow : true,
floating : false,
style : 'padding:5px',
height : 240,
frame : false,
viewConfig : {
forceFit : true
},
loadMask : true,
items : new Ext.grid.GridPanel({
border : false,
store : this.store4,
columns : [{
width : '75%',
dataIndex : 'title',
renderer : this.renderTitle
}, {
width : '25%',
dataIndex : 'date'
}]
                                    })
                        }, {
                            columnWidth : .30,
                            title : '系统操作说明书',
                            style : 'padding:5px;paddingLeft:0',
                            height : 240,
                            collapsible : true,
                            viewConfig : {
                                forceFit : true
                            },
                            hideHeaders : true,
                            frame : false,
                            loadMask : true,
                            items : new Ext.grid.GridPanel({
                                        border : false,
                                        store : this.store5,
                                        columns : [{
                                                    width : '70%',
                                                    dataIndex : 'title',
                                                    renderer : this.renderTitle
                                                }, {
                                                    width : '30%',
                                                    dataIndex : 'date'
                                                }]
                                    })
                        }, {
                            columnWidth : .35,
                            title : '系统第一次使用必读',
                            style : 'padding:5px;paddingLeft:0',
                            height : 240,
                            collapsible : true,
                            viewConfig : {
                                forceFit : true
                            },
                            hideHeaders : true,
                            loadMask : true,
                            frame : false,
                            items : new Ext.grid.GridPanel({
                                        border : false,
                                        store : this.store6,
                                        columns : [{
                                                    width : '75%',
                                                    dataIndex : 'title',
                                                    render : this.renderTitle
                                                }, {
                                                    width : '25%',
                                                    dataIndex : 'date'
                                                }]
                                    })
                        }]
            });this.add(this.containerPanel);
        },
        failure : function() {
            Ext.MessageBox.hide();
            Ext.MessageBox.show({
                        title : '系统提示',
                        msg : '加载首页数据时出错了!',
                        buttons : Ext.MessageBox.OK,
                        icon : Ext.MessageBox.WARNING
            });
        }
    });
},
readDetail : function(type, id) {
    if (!this.win) {
        this.win = this.createWin(700, 340, type);
    }
    this.win.show();
},
renderTitle : function(value, p, record) {
    return String.format(
                    '<b><a href="javascript:readDetail(\"{2}\",{0})">{1}</a></b><br/>',
                    record.id, value, record.type)
},
initComponent : function() {
    SXP.Ext.WelcomePage.superclass.initComponent.call(this);
    Ext.MessageBox.show({
                title : '请稍候',
                msg : '数据正在加载中....',
                icon : Ext.MessageBox.INFO,
                closable : false
    });
    this.on("render", this.buildComponent, this);
}

});
[/code]
恳请解答,3Q!

  • 写回答

4条回答 默认 最新

  • chem_zqm 2010-04-27 23:53
    关注

    你在290行的this指向的的是哪个对象呢?我告诉你吧,因为你没设定Ext.Ajax.request()这个方法的scope属性,所以this将指向window对象,然而window是没有add方法的,所以就有了你看到的错误,所以只要加个scope就可以了,如下:
    [code="js"]
    Ext.Ajax.request({
    url : 'util?cmd=loadOnStart',
    scope:this,
    ...
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用