简体   繁体   English

Kendo UI Treeview附加功能性能

[英]Kendo UI Treeview append function Performance

It looks like the performance of the following function is really bad. 看起来以下功能的表现非常糟糕。

treeView.append(children, parent);

Here treeView is Kendo UI Treeview, parent is container node for children and children is array of approximately 150 new nodes (my scenario). 这里TreeView的是剑道UI树视图, 父母对儿童和儿童容器节点是大约150新节点(我的方案)阵列。

And this code executes more than 7 seconds. 此代码执行超过7秒。

I guess the append function is not well implemented for a collection of items, so maybe there are some workarounds with generating html through jQuery, but Kendo UI Treeview should also know about new nodes to process future expand events for new nodes correctly. 我猜对于一组项目没有很好地实现append函数,所以也许有一些通过jQuery生成html的变通方法,但Kendo UI Treeview也应该知道新节点正确处理新节点的未来扩展事件。 Is there any way to improve the performance of the code above? 有没有办法改善上面代码的性能?

Thank you, Ihor 谢谢,Ihor

For those who encounter this problem: 对于遇到此问题的人:

Eventually I investigated Kendo UI source codes and instead of line from original post I used following code: 最后,我调查了Kendo UI源代码,而不是使用以下代码的原始帖子中的行:

 treeView.dataItem(parent).children.data(children)

That worked fine in my scenario. 在我的场景中,这很好用。

Performance is a pretty relative term. 表现是一个非常相对的术语。 If it takes 7 seconds, of course, it's not a good performance. 如果它需要7秒,当然,这不是一个好的表现。 In my computer append 150 new nodes took about one second but anyway I might suggest you some improvements. 在我的计算机中append 150个新节点花了大约一秒钟,但无论如何我可能会建议你做一些改进。

How do you append the nodes, one by one? 你如何逐个append节点?

for (var i = 0; i < 150; i++) {
    var added = { text:"node" + i };
    tree.append(added, parent);
}

try this instead (build an array with all the nodes to add and then invoke append ): 试试这个(构建一个包含要添加的所有节点的数组,然后调用append ):

var added = [];
for (var i = 0; i < 150; i++) {
    added.push({ text: "node" + i });
}
tree.append(added, parent);

In my computer it went from 1105ms to 787. Not that much but ... 在我的电脑里,它从1105ms变为787.不是那么多,但......

BUT , this is the time for inserting the nodes not the time that is needed for rendering. 但是 ,这是插入节点的时间而不是渲染所需的时间。 Is your problem append or render it on screen? 您的问题是append还是在屏幕上呈现?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM