extjs4如何调用controller?

转自:http://www.tuicool.com/articles/UreQFzQ

extjs mvc动态加载controller


原文  http://peihexian.iteye.com/blog/2028035



app.js


var application;


Ext.tip.QuickTipManager.init();


Ext.Loader.setConfig({
disableCaching:true,
enabled: true
});


application =new Ext.application({
requires: [
'Ext.window.MessageBox',
'Ext.container.Viewport'
],
name: 'app',
appFolder:'js/xxx/app',
autoCreateViewport:false,
controllers: [
'frameController'
],
launch: function() {
Ext.widget("main_viewport");
}
});


function refresh4Session()
{
Ext.Ajax.request({url: GLOBAL_ROOT_PATH+'/blank.jsp'});
    setTimeout(refresh4Session,5*60*1000);//五分钟
}
refresh4Session();
Ext.define('app.controller.frameController',{
extend : 'Ext.app.Controller',
alias : 'controller.frameController',
views : ['Viewport'],
refs:[
       {ref:'tabpanel',selector:'main_viewport>tabpanel[id=tabpanel]'}
   ],
init : function(application) {
var me = this;
window.application=me.getApplication();
me.control({
'main_viewport>panel[region=west]':{
render:function(obj){
var treepanel=Ext.create('Ext.tree.Panel',{
title:'test',
autoHeight:true,
autoScroll: true,
split: true,
rootVisible:false,
lines:true,
store: Ext.create('Ext.data.TreeStore', {
        root: {
        expanded: true,
        children: [
                  {text: '菜单名称', page: 'xxxxInfo_List', controller_full_class_name:'app.controller.xxxxInfo',leaf: true},
                  {text: '菜单名称', page: 'xxxxLevel_List',controller_full_class_name:'app.controller.xxxxLevel',leaf: true}
        ]
        }
}),
listeners: {
        'itemclick': function(view, record){
        if (!Ext.ClassManager.isCreated(record.raw.controller_full_class_name)) {
me.getApplication().getController(record.raw.controller_full_class_name);
                           }
if(record.isLeaf()){
    var id = 'tab-' + record.internalId;
    var center =  me.getTabpanel();//view.up('viewport').down('tabpanel');
    var tab = center.queryById(id);
    if(!tab){
    tab = center.add(Ext.widget(record.raw.page, {itemId: id, title: record.get('text'),closable : true}));
    }
    center.setActiveTab(tab);
    }
       }
}
});
obj.items.add(treepanel);
}
}
});
}
 
 });
上面的代码中,实现动态加载controller的最核心的其实就是


if (!Ext.ClassManager.isCreated(record.raw.controller_full_class_name)) {
                               me.getApplication().getController(record.raw.controller_full_class_name);
                           }
其他的就是mvc的正常的东西,比较简单了。


你可能感兴趣的:(ExtJS)