AngularJS/ng-grid - 使用splice更新数组不会更新UI

6 javascript angularjs angular-ui ng-grid

我正在尝试使用数组更新ng-gridsplice.我有一个普拉克这里.

添加按钮添加新行.更新按钮更新阵列中的最后一项.

  1. 选择一行并按更新按钮.什么都没发生.
  2. 按添加按钮.现在,UI使用新元素以及先前更新的元素进行更新.
  3. 同样的行为会一次又一次地重复.

我试过了$scope.$apply.我明白了:

"错误:$申请已在进行中"

我甚至尝试将$scope.$apply块放入setTimeout呼叫中.再次出现同样的错误!

任何指针!

谢谢!

Ste*_*wie 15

这是因为ng-grid中的数据$ watcher(错误地)比较了数据对象以供参考,而不是对象相等.您可以通过在data $ watch函数中将第三个参数设置为true来解决此问题(第3128行):

$scope.$parent.$watch(options.data, dataWatcher, true);
Run Code Online (Sandbox Code Playgroud)

Plunker

  • 我放弃了ngGrid.考虑尝试[智能表](https://github.com/lorenzofox3/Smart-Table). (3认同)