if *_*one 13 javascript angularjs angularjs-ng-repeat
我ng-repeat用来渲染一个html table.我的控制器看起来像这样:
app.controller("fooCtrl", function($scope, WebSocket) {
$scope.foo = [ ... ];
WebSocket.start(function(data) {
// this is a callback on websocket.onmessage
// here is a for loop iterating through $scope.foo objects and updating them
});
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我$scope.foo定期更新阵列.但是,我的视图构造如下:
<tr ng-repeat="item in foo">
...
</tr>
Run Code Online (Sandbox Code Playgroud)
问题是,当我更新时foo,它不会使用新数据重新呈现我的表.
我该如何解决这个问题?
lex*_*x82 25
你把更新包装好吗?
$scope.$apply(function() {
// update goes here
});
Run Code Online (Sandbox Code Playgroud)
?这应该可以解决问题.
| 归档时间: |
|
| 查看次数: |
21793 次 |
| 最近记录: |