$http 调用后无法刷新 ng-table。

unable to refresh ng-table after $http call.

在我的 SPA 中,我有一个激活函数,它有一个 promise getNodes()

        function activate() {
        var promises = [getNodes()];
        common.activateController(promises, controllerId)
            .then(function () { log('Activated Nodes List View'); });
    }

getNodes() 调用数据库以获取 'Node' 的列表,我正在从中制作一个分组的 ng-table。

    function getNodes() {
        return datacontext.getNodes().then(function (response) {
            $scope.data = response.data;
            $scope.$watch("query", function () {

                $scope.tableParams.reload();
            });
            $scope.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 10,          // count per page
                sorting: {
                    name: 'asc'
                }
            }, {
                groupBy: function (item) {

                    return item.NodeGroup.Name;
                },

                total: $scope.data,
                getData: function ($defer, params) {

                    var filteredData = new Array();
                    var func = (function () {
                        $scope.data.forEach(function (node) {
                            var is = !!((node.Name.toLowerCase().indexOf($scope.query || '') !== -1) || (node.IP.toLowerCase().indexOf($scope.query || '') !== -1) || (node.NodeGroup.Name.toLowerCase().indexOf($scope.query || '') !== -1));
                            if (is) {
                                filteredData.push(node);
                            }
                        });
                    })();

                    var orderedData = params.sorting() ?
                                        $filter('orderBy')(filteredData, params.orderBy()) :
                                         filteredData;

                    $scope.tableParams.total(orderedData.length);//this is also nto working for me. 
                    $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                },
                $scope: $scope
            });
        });

    }

发生的事情是,当 id 添加节点时,它不会更新我的 table。如果我刷新页面,我可以看到新添加的节点。但我希望我的 table 在添加后尽快刷新。

添加节点后,我再次调用激活,但没有成功。

    function addNode(node) {
        return datacontext.addNode(node).then(function (response) {
            activate();
        });

经过一番研究后,我添加了以下行。

            $scope.tableParams.total(orderedData.length);

这对我也不起作用。请帮忙。

我能够简单地通过更新我的添加和更新小说来修复我的添加和更新。

在添加的情况下,我在服务器成功调用添加后将新添加的对象推送到 $scope.data,然后调用

$scope.tableParams.reload();

在更新的情况下,我通过其 Id 找到要更新的对象,并在成功调用更新后将其替换为更新后的对象,然后调用 $scope.tableParams.reload();

但我的问题是,这是刷新 ng-table 的最佳方式还是我遗漏了什么?

    function addNode(node) {
        return datacontext.addNode(node).then(function (response) {
            $scope.data.push(node);
            $scope.tableParams.reload();
            //activate();
        });

    }

        function updateNode(node) {
        return datacontext.updateNode(node).then(function (response) {
            $scope.data.forEach(function (old) {
                var is = old.Id == node.Id;
                if (is) {
                    var index = $scope.data.indexOf(old);
                    $scope.data[index] = node;
                }
            });
            $scope.tableParams.reload();
        });

    }