AngularJS/ng-grid - 使用 splice 更新数组不会更新 UI [英] AngularJS/ng-grid - Updating array with splice doesn't updates UI

查看:34
本文介绍了AngularJS/ng-grid - 使用 splice 更新数组不会更新 UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新 ng-grid使用数组 splice.我有一个 plunk 这里.

I am trying to update ng-grid with array splice. I have a plunk here.

添加按钮添加新行.更新按钮更新数组中的最后一项.

Add button adds new row. Update button updates last item in the array.

  1. 选择一行&按更新按钮.没发生什么事.
  2. 按添加按钮.现在 UI 更新了新元素 &以及之前更新的元素.
  3. 同样的行为再次重复&

我尝试了 $scope.$apply.我得到:

错误:$apply 已经在进行中"

"Error: $apply already in progress"

我什至尝试将 $scope.$apply 块放在 setTimeout 调用中.又是同样的错误!

I even tried by placing $scope.$apply block inside a setTimeout call. Again the same error!

任何指点!

谢谢!

推荐答案

那是因为 ng-grid 中的数据 $watcher(错误地)比较数据对象以供参考,而不是对象相等性.您可以通过在 data $watch 函数(第 3128 行):

That's because data $watcher in ng-grid (incorrectly) compares the data object for reference, instead on object equality. You might remedy this by setting the third parameter to true in data $watch function (line 3128):

$scope.$parent.$watch(options.data, dataWatcher, true);

Plunker

这篇关于AngularJS/ng-grid - 使用 splice 更新数组不会更新 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆