ng-table 不适用于动态数据 [英] ng-table not working for dynamic data

查看:29
本文介绍了ng-table 不适用于动态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表,我正在使用 http 加载表中的数据.因此,在每次单击时,我的表数据都在发生变化,但我在表中看不到更新的数据.我创建了一个示例 Plunker 以供参考.在我的项目中,当我单击重新加载新数据"时,表中的数据已更改,但单击 2-3 次后它不会更改.有谁知道,如何修复它..

I have created a table and I am using http to load the data in the tables. So, in every click, my table data is changing, but I don't see the updated data in the table. I had created a sample Plunker for the reference. In my project, WHen I click on Reload New Data, the data in table get's changed, but after 2-3 click it doesn't change. DId anyone know, how to fix it..

推荐答案

这是 ngTable 指令的问题.它仅在 data.length 更改时更新.看看这个 plunk.我将 $scope['tableParams1'] 设置为 null 并在 $timeout 内设置新数据.这迫使 angularJs 做一个新的循环.因此,在第一个循环中 ngTable 看到 data.length 更改为 0,而在新循环中 ngTable 看到 data.length 再次更改.如果不使用 $timeout,ngTable 会看到 data.length 和之前一样,不会做任何事情.

It is a problem with the ngTable directive. It updates only when data.length changes. Take a look at this plunk. I set $scope['tableParams1'] to null and inside the $timeout I set the new data. This forces angularJs to do a new cycle. So in the first cycle the ngTable sees the data.length changed to 0 and in the new cycle the ngTable sees the data.length changed again. If you don't use the $timeout, the ngTable will see that the data.length remains the same as before and won't do nothing.

这篇关于ng-table 不适用于动态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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