您的位置:首页 > Web前端 > JavaScript

ExtJS 4动态加载组件

2011-05-24 17:02 337 查看
      这功能不错,相当使用,不用再为动态更换组件仇了,代码很简单就不多说了。

    加载组件
        
    
    
    
        /*在此添加样式代码*/
10      
11 
12     
13     
14     
15   
16          Ext.onReady(function(){
17              if(Ext.BLANK_IMAGE_URL.substr(0,4)!="data"){               
18                  Ext.BLANK_IMAGE_URL="./images/s.gif";
19              }
20   
21              //在此添加ExtJS代码
22              var panel=Ext.create("Ext.Panel",{
23                  renderTo:Ext.getBody(),
24                  layout:"auto",
25                  height:500,
26                  width:400,
27                  autoLoad:{
28                          url:"Component.js",
29                          renderer:"component"                       
30                  },
31                  tbar:[
32                      {text:"加载组件",scope:panel,handler:function(){
33                          panel.loader.load({
34                              url:"Component1.js",
35                              renderer:"component"
36                          })
37                      }},
38                      {text:"加载组件(removeAll)",scope:panel,handler:function(){
39                          panel.loader.load({
40                              url:"Component1.js",
41                              renderer:"component",
42                              removeAll:true
43                          })
44                      }}                   
45                  ]
46              });
47          });
48     
49 
50 
51   
 

       关键是autoLoad的定义,renderer可以设置渲染方式,渲染方式有3种:html、data和componet。html方式就是更新innerHTML,data复杂点,是以数据格式更新。componet呢则是使用组件的add方法添加组件。注意第二个按钮的removeAll属性,该属性为true会移除面板内原有的所有组件,然后再添加新的,这为更换grid的显示提供了一个便捷的方式。当然了,不用动态加载,直接使用组件的removeAll方法清除组件,然后使用add也是可以添加的。本文的目的是动态加载,所以就这样使用而已。

 

      Componet1.js

{xtype:'panel',height:100,width:90,html:"新增的组件"}
 

      Componet.js    

 

{xtype:'panel',height:100,width:200,html:"原有的组件"}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: