一个简单的tree,约250个节点,点击根展开收缩,每次都会引起IE内存增加,怎么处理?

解决方案 »

  1.   

    extjs原来既有性能问题,不过也要看你实际怎么用
      

  2.   

    麻烦帮看下:t.j.treeClass=function(cfg){
    this.tbar={
    items:[
    {xtype:"tbspacer",style:'width:5px;'},
    new Ext.form.TextField({
    ref:'../searchKey',
    width: 110,
    emptyText:'请输入查询内容',
    enableKeyEvents:true,
    listeners:{
    keyup:function(f,e){
    if(e.getKey()==Ext.EventObject.ENTER){
    f.ownerCt.ownerCt.queF();
    }
    }
    }
    }), '->',
    new t.j.b.que({scope:this}),
    {xtype:"tbspacer",style:'width:5px;'}
    ]
    };
    this.tools=[
    {
    id:'refresh',
    handler:function(e,t,p,o){p.loadTree('refresh')}
    }
    ];
    t.j.treeClass.superclass.constructor.call(this,cfg);
    };Ext.extend(t.j.treeClass,Ext.tree.TreePanel,{
        region:'west',
        animCollapse:false,
        animate: false,
        autoDestroy:true,
        split:true,
        width:250,
        minSize:200,
        maxSize:350,
        collapsible:true,
        collapseFirst:false,
        titleCollapse:true,
        autoScroll:true,
        title:t.g.COM.name,
        loader: new Ext.tree.TreeLoader({}),
        rootVisible: false,
        queF:function(){
         if(this.searchKey.getValue().trim().length<=0)return;
         var node=this.searchNode(this.searchKey.getValue(),'depth'),nid;
         if(node==null)return;
         nid=node.id;
         node=this.getOriginalNodePathById(node.id);
         if(node==null)return;
         node='/'+node;
         this.selectPath(node);
         node=this.getNodeById(nid);
         this.body.scrollIntoView(node.ui.anchor);
         if(node)this.fireEvent('click',node);
         node=nid=null;
        },
        loadTree:function(sm,url,callback){
         var me=this,s=new Date();
         t.i.mask(me,'数据加载中……','busy');
         try{if(me.requestId&&Ext.Ajax.isLoading(me.requestId))Ext.Ajax.abort(me.requestId);}
         catch(ex){}
         me.requestId=Ext.Ajax.request({
    url:url||'getTree.do',
    params:{
    comNo:'C'+t.g.COM.no,
    selectMode:sm||''
    },
    method:'POST',
    timeout:10*60*1000,
    success:function(response){
    var text=response.responseText.replace(/\n\r|\n|\r/g,'');
    if(text=='logout'){
    t.j.msg.showInfo('请重新登录',function(){
    window.location.href='../login.html';
    },'登录超时');
    return false;
    }
    var x;
    try{
    x=Ext.decode(text);
    t.g.tree.setRootNode(new Ext.tree.AsyncTreeNode(x));
    }
    catch(ex){}
    finally{
    text=null;
    x=null;
    if(Ext.isFunction(callback))callback(me);
    else t.i.setStatus('导航树加载成功,共用时'+(new Date()-s)/1000+'秒','success');
    t.i.unmask(me);
    me=s=null;
    }
    },
    failure:function(response){
    if(Ext.isFunction(callback))callback(me);
    else t.i.setStatus('导航树加载失败,共用时'+(new Date()-s)/1000+'秒','success');
    t.i.unmask(me);
    me=s=null;
    }
    });
        }
    });t.g.tree=new t.j.treeClass({
        root: new Ext.tree.AsyncTreeNode({
            expanded: true
        }),
        margins:'0 0 0 2',
        collapsed:true,
        listeners:{
    click:function(n){
             alert(n.attributes.pid);
    }
        }
    });
    t.g.tree.loadTree();

      

  3.   

    谢谢楼上的哥,贴一段数据:root={
       id:'root',
       text:'根',
       children:[
       {id:'c1',text:'第一类',icon:'../images/class1.png',leaf:false,vol:400,rid:'..',children:[……]},
       {id:'c2',text:'第二类',icon:'../images/class2.png',leaf:false,vol:200,rid:'..',children:[……]},
       ……
       ]
    }下面还有,然后每类都还有子节点,节点样子都差不多,leaf属性除了叶节点都为false,叶节点为true。叶节点的children为空数组
      

  4.   

    建议不要用icon属性,换成iconCls,因为每一个icon都会生成一个img标签,有点占资源,换成iconCls只是要求写一个样式,会节省很多资源。如果用icon,每次加载树都会去删除原来的img,再添加新的img。添加删除img标签对于IE来说可能有点不太妥当。
      

  5.   

    其实ext的异步树也挺好用的啊,一次只加载一个节点下面的子节点