日期:2014-05-16 浏览次数:20510 次
先来看看模块基类的代码:
//定义程序的命名空间
Ext.namespace('demo');
demo.module = function(main){
    this.main = main;
    this.init();
}
Ext.extend(demo.module, Ext.util.Observable, {
    init : Ext.emptyFn
});
demo.app = function(){    
    this.init();
}
Ext.extend(demo.app, Ext.util.Observable, {
    init: function(){       
        this.tab1 =  new Ext.Panel({
            title: '模块一',
            id: 'module1',
            layout: 'fit'
        });
        
        this.tab2 =  new Ext.Panel({
            title: '模块二',
            id: 'module2',
            layout: 'fit'
        });
        this.tab3 =  new Ext.Panel({
            title: '模块三',
            id: 'module3',
            layout: 'fit'
        });
        this.body = new Ext.TabPanel({
            region:'center',
            margins:'0 5 0 5',
            autoScroll: true,
            items: [this.tab1, this.tab2, this.tab3]
        });
        var viewport = new Ext.Viewport({
            layout:'border',
            items:[
                new Ext.BoxComponent({region:'north', el:'header', height:60}),
                new Ext.BoxComponent({region:'south', el:'footer', height:50}),
                this.body
            ]
        });
        this.body.on('tabchange', this.tabActive, this);
        this.loadMask = new Ext.LoadMask(this.body.body);
        this.body.activate(this.tab1);
    },
    tabActive: function(p,t){
        if(this[t.id]){
            return false;
        }
        this.loadMask.show();
        Ext.Ajax.request({
            method:'GET',
            url: 'modules/'+t.id+'.js',
            scope: this,
            success: function(response){
                var module = eval(response.responseText);
                this[t.id] = new module(t);
                this.loadMask.hide();
            }
        });
    }
});
Ext.onReady(function(){
    Ext.QuickTips.init();
    myApp = new demo.app();
});