简体   繁体   English

angularjs ngrepeat插入批处理

[英]angularjs ngrepeat insert batch

Is it just me or does ng-repeat DOM inserts not batch. 是我还是ng-repeat DOM插入不批量。 As we all know DOM manipulation is slow and operations should be batched for performance. 众所周知,DOM操作速度很慢,应该分批操作以提高性能。 When using ng-repeat on a collection it should create the DOM elements in memory and then insert them all at once instead of inserting them one at a time. 在集合上使用ng-repeat时,应在内存中创建DOM元素,然后将它们全部一次插入,而不是一次插入一个。

Is there any advice on how to get this behavior? 关于如何获得这种行为有什么建议吗?

There is a very good answer about angular's databinding , from one of its creators. 一位创建者对angular的数据绑定有一个很好的答案

See the comment below, where he explains why angular's dirty-checking approach is better than change listeners: 请参阅下面的评论,他在其中解释了为何angular的脏检查方法比更改侦听器更好:

Change coalescence. 更改合并。 Suppose you have an array of items. 假设您有一组项目。 Say you want to add items into an array, as you are looping to add, each time you add you are firing events on change, which is rendering the UI. 假设您想将项目添加到数组中,就像您要循环添加一样,每次添加时,您都会触发更改事件,即呈现UI。 This is very bad for performance. 这对性能非常不利。 What you want is to update the UI only once, at the end . 您想要的是在末尾仅更新一次UI The change events are too fine grained. 更改事件的粒度太细了。

In other words, thanks to this dirty-checking approach, angular is already updating the UI only once, with all DOM changes. 换句话说,由于采用了这种脏检查的方法,angular已经在所有DOM更改的情况下仅一次更新了UI。

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

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