AngularJS-我如何观察一个深层嵌套的数组? [英] AngularJS - How can I $watch a deeply nested array?
本文介绍了AngularJS-我如何观察一个深层嵌套的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有如下数据:
$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);
推荐答案
范围$watch
深度
Scope $watch
Depths
$scope.$watch('boardLists', function(newVal, oldVal){
console.log(newVal);
console.log(oldVal);
}, true);
使用$scope.$watch('item',fn,true);
进行深入观察.
有关信息,请参见 AngularJS开发人员指南-$scope
观看深度.
For information, see AngularJS Developer Guide - $scope
Watch Depths.
这篇关于AngularJS-我如何观察一个深层嵌套的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文