简体   繁体   English

ngTable中未更新动态数据

[英]Dynamic data is not updated in a ngTable

I'm using the ngTable directive and the problem is that the data doesn't refresh in the table. 我正在使用ngTable指令,问题是表中的数据没有刷新。

When loading the page, the gemId is undefined and no data shows which is ok. 加载页面时,gemId是未定义的,没有数据显示可以。

Then you select a value from a dropdown and when pressing a button the loadItems function is called. 然后,从下拉列表中选择一个值,并在按下按钮时调用loadItems函数。 Data is retrieved from the server but does not show in the table. 数据是从服务器检索的,但未显示在表中。 When I filter a column, the data is shown (= 2nd request ). 当我过滤列时,将显示数据(=第二个请求)。

 $scope.tblProject = new ngTableParams(tableParameters, {
    counts: [], // hide page counts control
    total: $scope.items.length,  // value less than count hide pagination
    //defaultSort: ['asc','desc'];
    getData: function ($defer, params) {
        //opgelet: request is geldig ondanks de onbestaand igeID;
        var gemId = modelFactory.getGemeente().id;
        var igeId = 22222;

        if(!angular.isUndefined(gemId)){
            Project.query({gemId: gemId, igeId: igeId}, function (projecten) {
                var orderedData = params.sorting() ? $filter('orderBy')(projecten, params.orderBy()) : projecten;
                $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));

            });
        }
    },
    $scope: { $data: {} } //see example 14
});


 $scope.$on('loadItems',function() {
    $scope.tblProject.reload();
});

Tried all the possible work-arounds for refreshing the table so far, but have had no luck. 到目前为止,尝试过所有可能的解决方法以刷新表,但是都没有运气。

edit: I think it is a scope problem when executing the 'loadItems' 编辑:我认为这是执行'loadItems'时的范围问题

问题是我正在使用$ emit而不是$ broadcast将事件从parentController发送到childController,该事件执行'loadItems'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM