+ -
当前位置:首页 → 问答吧 → append方法效率太差了,高手帮忙看下

append方法效率太差了,高手帮忙看下

时间:2009-03-26

来源:互联网

function drawDataSourceBodyTable(){
    var dataSourceBodyTableTr=I('dataSourceBodyTable tr[id]');    
    dataSourceBodyTableTr.remove();    

    var row,cell,dataIndex,dataObject,timeYMD,dataLevel,innerText,appendHTML;
    
    for(dataIndex=0;dataIndex<dataSource.length;dataIndex++){
        appendHTML="";        
        dataObject=dataSource[dataIndex];
        dataLevel=getDataLevelByVersion(dataObject.version);
        innerText=dataIndex+1;
        I('dataSourceBodyTable').append("<tr id='row_"+dataIndex+"' rid='"+dataIndex+"' dataLevel='"+dataLevel+"' style='height:"+gantShowTdHeight+"px;'></tr>");

        
        appendHTML="<td id='"+dataIndex+",0"+"' style='width:30px;backgroundColor:whitesmoke'>"+innerText+
        "</td><td id='"+dataIndex+",1"+"' style='width:270px'><table border='0' cellspacing='0' cellpadding='0'><tr><td style='width:"+parseInt(dataLevel*20)+"px'></td><td style='borderWidth:0'>";
        if(dataSource[dataIndex+1]!=null&&getDataLevelByVersion(dataSource[dataIndex+1].version)>dataLevel){
            dataSourceBodyTableTr.attr('isSummary','1');
            appendHTML+="<img id='img_"+dataIndex+"'  src='"+openDir+"' onclick='changeTree()' rid="+dataIndex+">";            
        }
        else{
            appendHTML+='';
            dataSourceBodyTableTr.attr('isSummary','0');
        }
        appendHTML+="</td><td style='borderWidth:0px'>"+dataObject.taskName.substr(0,20)+"</td></tr></table></td>";
        
        appendHTML+="<td id='"+dataIndex+",2"+"' style='Width:100px'>"+getDaysBetweenStartAndEnd(dataObject.planStart,dataObject.planEnd)+"</td>";
        
        timeYMD=dataObject.planStart.split('-');
        I('row_'+dataIndex).attr('planStart',settimeSpanStart(timeYMD));
        appendHTML+="<td id='"+dataIndex+",3"+"' style='Width:100px'>"+timeYMD[0]+'年'+timeYMD[1]+'月'+timeYMD[2]+'日'+"</td>";
            
        timeYMD=dataObject.planEnd.split('-');
        appendHTML+="<td id='"+dataIndex+",4"+"' style='Width:100px'>"+timeYMD[0]+'年'+timeYMD[1]+'月'+timeYMD[2]+'日'+"</td>";
        
        appendHTML+="<td id='"+dataIndex+",5"+"' style='Width:100px'>"+dataObject.resources.substr(0,8)+"</td>";
        I('row_'+dataIndex).attr('planEnd',settimeSpanEnd(timeYMD));
        I('row_'+dataIndex).attr('excuteStart',getTimeByYMD(dataObject.excuteStart.split('-')));
        I('row_'+dataIndex).attr('excuteEnd',getTimeByYMD(dataObject.excuteEnd.split('-')));
        I('row_'+dataIndex).attr('resources',dataObject.resources);
        I('row_'+dataIndex).attr('level',dataLevel);
        I('row_'+dataIndex).html(appendHTML);
        
    }
    realTimeStart=timeSpanStart;
    realTimeEnd=timeSpanEnd;
}

作者: xwz7534658   发布时间: 2009-03-26

少用append方法
先创建数据字符串
最后调用一次append添加到document当中

可以看论坛这个帖子 我在2楼的回帖
http://bbs.jquery.org.cn/read.php?tid-4206.html

作者: gordianyuan   发布时间: 2009-03-26