angularjs – Angular JS ng-repeat消耗更多的浏览器内存

前端之家收集整理的这篇文章主要介绍了angularjs – Angular JS ng-repeat消耗更多的浏览器内存前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下代码
<table>
 <thead><td>Id</td><td>Name</td><td>Ratings</td></thead>
 <tbody>
   <tr ng-repeat="user in users">
    <td>{{user.id}}</td>
    <td>{{user.name}}</td>
    <td><div ng-repeat="item in items">{{item.rating}}</div></td>
   </tr>
 </tbody>
</table>

users是一个只有id和name的用户对象数组.数组中的用户对象数 – 150

items是一个只有id和rating的项目对象数组.数组中的项目对象数 – 150

当我在浏览器中渲染它时,当我在我的chrome-v23.0.1271.95中尝试分析时,它需要大约250MB的堆内存.

我正在使用AngularJS v1.0.3.

有角度的问题还是我在这里做错了什么?

这是JS小提琴

http://jsfiddle.net/JSWorld/WqSGR/5/

好吧,这不是ng-repeat本身.我认为你正在使用{{item.rating}}添加绑定.

所有这些绑定都在范围内注册,因此:

> 150 * 2 = 300(对于2个用户的信息)
> 150 * 150 = 22500(评级信息)
> 22800个手表功能共22800个dom元素.

这会将内存推到250MB的可想象值

Databinding in angularjs

You can’t really show more than about 2000 pieces of information to a human on a single page. Anything more than that is really bad UI,and humans can’t process this anyway.

原文链接:https://www.f2er.com/angularjs/142189.html

猜你在找的Angularjs相关文章