首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jsPlumb提高执行速度

jsPlumb提高执行速度
EN

Stack Overflow用户
提问于 2013-03-31 18:47:09
回答 1查看 1.1K关注 0票数 2

我正在使用jsPlumb库来绘制(连接)一些div。divs的数量是动态的,最多可达2000个div。我使用下面的递归方法来划清界限:

代码语言:javascript
复制
connectGraphNodes: function(jsp_o, children, level){
    var nr_of_children, i=0;

    nr_of_children = children.length;
    for(i=0; i<nr_of_children; i++){
        if(!this.isPropertyEmpty(children[i]['id']) && !this.isPropertyEmpty(children[i]['name'])){
            // Connect child node with node
            jsp_o.connect({ 
                source: 'es-org-graph-box-' + children[i]['parent'], 
                target: 'es-org-graph-box-' + children[i]['id'],
               overlays:[
                    [ "Label", {
                            label: children[i]['percentage']+'%', id:"label",
                            location: 1                                
                        }
                    ]
                ]   
            });

            if(this.isSet(children[i]['children']) && children[i]['children'].length > 0){
                level++;
                // Run recurence function for child-nodes
                jsp_o.setSuspendDrawing(true);
                this.connectGraphNodes(jsp_o, children[i]['children'], level);
                jsp_o.setSuspendDrawing(false, true);
            }
        }            
    }
}

我的问题是,对于一个大于100的数字,加载时间非常长,有些时候google chrome会弹出一个关闭标签选项。我可以对我的方法做些什么改进吗?或者jsPlumb有那么慢?

EN

回答 1

Stack Overflow用户

发布于 2014-02-13 22:53:19

就像Rich已经提到的,你必须利用

代码语言:javascript
复制
jsPlumb.setSuspendDrawing(); 

方法

试试这个:

代码语言:javascript
复制
connectGraphNodes: function(jsp_o, children, level){
    var nr_of_children, i=0;

    nr_of_children = children.length;
    //start of suspend drawing
    jsPlumb.setSuspendDrawing(true);
    for(i=0; i<nr_of_children; i++){
        if(!this.isPropertyEmpty(children[i]['id']) && !this.isPropertyEmpty(children[i]['name'])){
            // Connect child node with node
            jsp_o.connect({ 
                source: 'es-org-graph-box-' + children[i]['parent'], 
                target: 'es-org-graph-box-' + children[i]['id'],
               overlays:[
                    [ "Label", {
                            label: children[i]['percentage']+'%', id:"label",
                            location: 1                                
                        }
                    ]
                ]   
            });

            if(this.isSet(children[i]['children']) && children[i]['children'].length > 0){
                level++;
                // Run recurence function for child-nodes
                jsp_o.setSuspendDrawing(true);
                this.connectGraphNodes(jsp_o, children[i]['children'], level);
                jsp_o.setSuspendDrawing(false, true);
            }
        }            
    }
    //end of suspend drawing
    jsPlumb.setSuspendDrawing(false,true);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15728616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档