使用一次性绑定的 ng-repeat - 届时跟踪对性能有影响吗?
ng-repeat using one-time binding - does track by then have an impact on performance?
正如我在此处阅读的那样 (performance of $interpolate vs ng-repeat and one time binding),具有指令 ng-repeat
和使用一次性绑定在性能方面几乎相等。如有不妥请指正!
这意味着,当在 ng-repeat
上使用一次性绑定时,属性 track by
不会添加任何值,对吗?或者它实际上在性能方面对我有帮助,因为 ng-repeat
否则仍会在 $$hashKey
处生成索引?
This means, that when using one-time binding on ng-repeat, the attribute track by doesn't add any value, right?
track by
与一次性绑定没有关联。
- 一次性绑定减少观察者数量
track by
不会重新呈现 DOM 一旦您的列表从服务器更新并且它们没有变化(可以说基于项目的 id
)
ng-repeat
a.e 中的一次性绑定。 ng-repeat="friend in ::friends"
将在它们稳定后停止重新计算 friends
,这发生在第一个摘要循环之后(如果表达式结果是非未定义的值)。
例如:
<li ng-repeat="friend in ::friends ">{{friend.name}}</li>
和:
$scope.friends = [{
id: 0,
name: 'Ben'
}];
$timeout(function(){
$scope.friends.push({
id: 3,
name: 'Chen'
});
},1000);
结果:
你会看到 Ben
但在延迟 1 秒后没有任何变化,因为一次性绑定停止了 ng-repeat
观察者。我们通常将其用于固定列表。
顺便说一句,它适用于列表项目计数而不是项目本身。
一次性绑定不会解除$$hashKey
但是你可以这样写:
<li ng-repeat="friend in ::friends track by friend.id">
正如我在此处阅读的那样 (performance of $interpolate vs ng-repeat and one time binding),具有指令 ng-repeat
和使用一次性绑定在性能方面几乎相等。如有不妥请指正!
这意味着,当在 ng-repeat
上使用一次性绑定时,属性 track by
不会添加任何值,对吗?或者它实际上在性能方面对我有帮助,因为 ng-repeat
否则仍会在 $$hashKey
处生成索引?
This means, that when using one-time binding on ng-repeat, the attribute track by doesn't add any value, right?
track by
与一次性绑定没有关联。
- 一次性绑定减少观察者数量
track by
不会重新呈现 DOM 一旦您的列表从服务器更新并且它们没有变化(可以说基于项目的id
)
ng-repeat
a.e 中的一次性绑定。 ng-repeat="friend in ::friends"
将在它们稳定后停止重新计算 friends
,这发生在第一个摘要循环之后(如果表达式结果是非未定义的值)。
例如:
<li ng-repeat="friend in ::friends ">{{friend.name}}</li>
和:
$scope.friends = [{
id: 0,
name: 'Ben'
}];
$timeout(function(){
$scope.friends.push({
id: 3,
name: 'Chen'
});
},1000);
结果:
你会看到 Ben
但在延迟 1 秒后没有任何变化,因为一次性绑定停止了 ng-repeat
观察者。我们通常将其用于固定列表。
顺便说一句,它适用于列表项目计数而不是项目本身。
一次性绑定不会解除$$hashKey
但是你可以这样写:
<li ng-repeat="friend in ::friends track by friend.id">