1、在admin.jsp中引入ExtJS4.0.2的类:

  1. <link rel="stylesheet" type="text/css" href="../ext-4.0.2/resources/css/ext-all.css" /> 
  2. <script type="text/javascript" src="../ext-4.0.2/bootstrap.js"></script>  
  3. <script type="text/javascript" src="../ext-4.0.2/locale/ext-lang-zh_CN.js"></script> 

注意:引顺序(ext-lang-zh_CN.js须在bootstrap.js后引入),bootstrap.js会根据是否是开发环境判断加载ext-all.js还是ext-all-debug.js。

 

2、admin.js

  1. Ext.Loader.setConfig({enabled:true}); //Ext默认是不开启动态加载的。当引用到其他js类时,需要开启动态加载 
  2. Ext.Loader.setPath('MyApp''../houtai/js');  //将路径设置为一个命名空间。 
  3. Ext.require('MyApp.views.Viewport');  //加载所需要的类或类库。 
  4.   
  5. Ext.onReady(function() {      
  6.   Ext.create('MyApp.views.Viewport').show(); //ExtJS4是面向对象的,create相当于new一个类对象,实例化一个类。 
  7. });    

 

3、Viewport.js

 

  1. Ext.define('MyApp.views.Viewport', {  //define定义一个类 
  2.     extend: 'Ext.container.Viewport',  //extend 继承自一个父类 
  3.     requires:['MyApp.stores.TreeStore'],   
  4.     layout: {  
  5.         type: 'border'  
  6.     },  
  7.   
  8.     initComponent: function() {  //构造函数 
  9.         var me = this;   
  10.         var store   = MyApp.stores.TreeStore;  
  11.   
  12.         Ext.applyIf(me, {   //将所有me没有的配置属性复制给me 
  13.             items: [  
  14.                 {  
  15.                     xtype: 'container',  
  16.                     height: 25,  
  17.                     region: 'north'  
  18.                 },  
  19.                 {  
  20.                     xtype: 'treepanel',  
  21.                     id: 'west-panel',  
  22.                     store:store,   
  23.                     margin: '0 0 0 0',  
  24.                     maxWidth: 400,  
  25.                     minWidth: 185,  
  26.                     width: 200,  
  27.                     title: '后台菜单',  
  28.                     region: 'west',  
  29.                     split: true,  
  30.                     collapsible :true,  
  31.                     viewConfig: {  
  32.                         border: 'false',  
  33.                         id: '主菜单',  
  34.                         autoScroll: true  
  35.                     }  
  36.                  },  
  37.                 {  
  38.                     xtype: 'tabpanel',  
  39.                     frame: true,  
  40.                     id: 'tab',  
  41.                     resizable: true,  
  42.                     activeTab: 0,  
  43.                     minTabWidth: 115,  
  44.                     maxTabWidth: 135,  
  45.                     region: 'center',  
  46.                     items: [  
  47.                         {  
  48.                             xtype: 'panel',  
  49.                             title: '基站状态显示'  
  50.                         }  
  51.                     ]  
  52.                 },  
  53.                 {  
  54.                     xtype: 'container',  
  55.                     height: 20,  
  56.                     region: 'south'  
  57.                 }  
  58.             ]  
  59.         });  
  60.   
  61.         me.callParent(arguments);  
  62.     }  
  63. });  

 

4、TreeStore.js

 

  1. Ext.define('MyApp.stores.TreeStore', {  
  2.     extend    : 'Ext.data.TreeStore',  
  3.     singleton : true,   //此类实例化为单态 
  4.     root:{  
  5.         expanded: true,   
  6.         text:"菜单",  
  7.         user:"",  
  8.         status:"",  
  9.         children: [  
  10.             {id:"x",text:"detention",leaf: true},  
  11.             {text:"book", leaf: true },  
  12.             {text:"alegrbra", leaf: true},  
  13.             {text: "buy", leaf:true }  
  14.         ]  
  15.     }  
  16.     });  

 

另:alias用法

  1. Ext.define('MyApp.views.UsersGridPanel', {  
  2.     extend   : 'Ext.grid.Panel',  
  3.     alias    : 'widget.UsersGridPanel'//类的部件名称,可做xtype 
  4.     requires : ['MyApp.stores.UserStore'],  
  5.   
  6. 如:
  7.  
  8.    xtype     : 'UsersGridPanel'
  9.    width     : 280, 
  10.    itemId    : 'userGrid'