[英]Binding won't update when objects change
I have an array that is, basically, a subset of another array: 我有一个数组,基本上是另一个数组的子集:
$scope.theFew = $scope.theMany.filter(function(obj, index, array) {
return obj.IsVerySpecial;
});
Elsewhere in my controller, I have some functions that act on theMany
array, changing the IsVerySpecial
property. 在控制器的其他地方,我有一些作用于theMany
数组的函数,更改了IsVerySpecial
属性。
I'd expect $scope.theFew
to update when objects within $scope.theMany
have their properties change, but that isn't the case. 我期望$scope.theFew
更新时中的对象$scope.theMany
有自己的特性发生变化,但事实并非如此。 What's going on? 这是怎么回事?
A quick discovery on this, but it worked. 对此有一个快速发现,但确实有效。 To be fair, this was some older code ;) 公平地说,这是一些较旧的代码;)
The code should instead read: 该代码应改为:
$scope.theFew = function() {
return $scope.theMany.filter(function(obj, index, array) {
return obj.IsVerySpecial;
});
}
I too had a similar issue. 我也有类似的问题。 I have used the $watch to update scope variables. 我已经使用$ watch更新范围变量。 Not sure if this is the best way. 不知道这是否是最好的方法。
controller: ['$scope', function($scope) {
updateVisualData();
$scope.$watch("data", function(newData) {
console.log("new Data in paContent");
console.log(newData);
updateVisualData();
}, true);
function updateVisualData() {
var contentData = $scope.data.components && $scope.data.components.filter(function(item) {
return item.type === "Layout";
});
if (contentData && contentData.length > 0) {
contentData = contentData[0];
$scope.graphType = contentData.graph.type;
$scope.graphData = contentData.graph.graphData;
-----
}
}
}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.