简单的方法为NG-重复绑定? [英] Simple One way binding for ng-repeat?

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

问题描述

我看过一些文章,说纳克重复会导致业绩不佳,如果有超过2000个项目,因为有太多的双向绑定观看。我是新来angularjs和无法理解NG重复和双向绑定的关系是:


  1. 请问NG-重复(如输出JSON对象的列表)去创造双向绑定?


  2. 有一个简单的方法来做到纳克重复使用只有一个办法约束力? (preferably不需要外部模块)



解决方案

像user1843640提到的,如果你对角1.3,可以使用一次性的结合,但是,仅仅是为了清楚,你需要把::上的所有绑定,而不仅仅是转发器。该文件说做到这一点:

< D​​IV NG重复=项::项目> {{item.name}}< / DIV>

但是,如果我算观察家,这只是删除了一个。要真的降双向绑定的数量,将::在中继器内的绑定,就像这样:

< D​​IV NG重复=项::项目> {{:: item.name}}< / DIV>

下面是两个plunkers将显示观察家数:

所有绑定

直放站只有

感谢出去Miraage为provinding功能来算观察家<一个href=\"http://stackoverflow.com/a/23470578/2200446\">http://stackoverflow.com/a/23470578/2200446

I have read some articles that said ng-repeat would led to poor performance if there is over 2000 items, because there are too many two way binding to watch. I am new to angularjs and have trouble understanding the relationship between ng-repeat and two-way binding:

  1. Does ng-repeat (like outputting a list of json objects) necessarily create two way binding?

  2. Is there a simple way to do ng-repeat using only one way binding? (preferably do not need external module)

解决方案

Like user1843640 mentioned, if you are on Angular 1.3, you can use one-time-binding, but, just for clarity, you need to put the :: on all the bindings, not just the repeater. The docs say do this:

<div ng-repeat="item in ::items">{{item.name}}</div>

But, if I count the watchers, this only removed one. To really drop the number of two-way-bindings, place the :: on the bindings within the repeater, like this:

<div ng-repeat="item in ::items">{{::item.name}}</div>

Here are two plunkers that will display the number of watchers:

All Bindings
Repeater Only

Thanks goes out to Miraage for provinding the function to count the watchers http://stackoverflow.com/a/23470578/2200446

这篇关于简单的方法为NG-重复绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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