嵌套NG-重演 [英] Nested ng-repeat performance

查看:120
本文介绍了嵌套NG-重演的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说有嵌套NG-重复在角严重影响性能,如果它导致了大量与它们的角前pressions元素。其实我也碰到这种情况下,一些code,我试着写。我尝试使用 bindonce 以提高性能,但它并没有太大的帮助。我听说,你可以用一个指令来帮助性能,但同时我之前写的指令,我不知道如何使用指令来改善这样的表现。 这里是展示问题的jsfiddle。

I have heard that having nested ng-repeats can seriously impact performance in angular if it results in a large number of elements with angular expressions in them. I actually have run into this case with some code I'm trying to write. I tried using bindonce to improve the performance, but it didn't help much. I have heard that you can use a directive to help with performance, but while I've written directives before, I'm not sure how to use a directive to improve the performance of something like this. Here is a jsfiddle demonstrating the problem.

我意识到,这是数据了很多,真的,我应该做一些分页,但我想更多地了解角度和性能。我可以使同样的数据,而无需角和页面呈现速度更快。

I realize that it is A LOT of data and really, I should be doing some sort of pagination, but I'm trying to learn more about Angular and performance. I can render this same data without Angular and the page renders much faster.

下面是嵌套NG-重复如下:

Here is what the nested ng-repeats look like:

<div ng-app="app" ng-controller="myController">
<div ng-repeat="module in modules">
    {{module.title}}
    <div ng-repeat="clip in module.clips">
        {{clip.title}}<br/>
        <a ng-repeat="transcript in clip.transcripts" href="transcript.href">{{transcript.text}}</a><br/>
    </div>
</div>

谢谢!

推荐答案

尝试使用按部就班地进行,这将确保节点不会破坏并重新创建的DOM!下面是本纳德尔有关此主题的大文章:

Try using track by this will ensure the dom nodes are not destroyed and recreated! Here is great article from Ben Nadel on this topic:

http://www.bennadel.com/blog/2556-using-track-by-with-ngrepeat-in-angularjs-1-2.htm

这篇关于嵌套NG-重演的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆