AngularJS - 如何 $watch 深度嵌套的数组? [英] AngularJS - How can I $watch a deeply nested array?
本文介绍了AngularJS - 如何 $watch 深度嵌套的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前的数据如下所示:
I currently have data that looks like the following:
$scope.boardLists = [{
cards: [{a:1, b:2}, {a:2, b:2}]
},
{
cards: [{a:3, b:3}, {a:4, b:4}]
},
{
cards: [{a:5, b:5}, {a:6, b:6}]
}];
如何观察卡片数组的变化?
How can I watch for changes in the cards array?
到目前为止,我已经尝试了以下方法:
I have tried the following so far:
$scope.$watchCollection('boardLists', function(newVal, oldVal){
console.log(newVal);
console.log(oldVal);
});
$scope.$watch('boardLists', function(newVal, oldVal){
console.log(newVal);
console.log(oldVal);
}, true);
推荐答案
Scope $watch
Depths
Scope $watch
Depths
$scope.$watch('boardLists', function(newVal, oldVal){
console.log(newVal);
console.log(oldVal);
}, true);
使用 $scope.$watch('item',fn,true);
进行深度观察.
Use $scope.$watch('item',fn,true);
for a deep watch.
有关信息,请参阅 AngularJS 开发人员指南 - $scope代码>观察深度
.
For information, see AngularJS Developer Guide - $scope
Watch Depths.
这篇关于AngularJS - 如何 $watch 深度嵌套的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文