AngularJS: Ngtable 重新加载到旧数据

AngularJS: Ngtable reload to old data

所以我使用 NGTable 在我的页面上显示数据,数据存储在一个数组中并通过数据集参数传递,但是当我以编程方式更改数组中数据的值时,更改会正确显示在table BUT 当我转到第二页并再次转到第一页时 table 显示旧数据。

这里有一个 JSFiddle 可以说明我的问题:http://jsfiddle.net/vqxscmsu/

    angular.module("uCloud", ["ngTable"])
  .controller("myController", myController);

myController.$inject = ["NgTableParams", "$scope"];

function myController(NgTableParams, $scope) {

        $scope.fsck = [{
      name: "teste1",
      description: "testando1"
    }, {
      name: "teste2",
      description: "testando2"
    }, {
      name: "teste3",
      description: "testando3"
    }, {
      name: "teste4",
      description: "testando4"
    }, {
      name: "teste2",
      description: "testando2"
    }, {
      name: "teste3",
      description: "testando3"
    }, {
      name: "teste4",
      description: "testando4"
    }, {
      name: "teste2",
      description: "testando2"
    }, {
      name: "teste3",
      description: "testando3"
    }, {
      name: "teste4",
      description: "testando4"
    }, {
      name: "teste2",
      description: "testando2"
    }, {
      name: "teste3",
      description: "testando3"
    }, {
      name: "teste4",
      description: "testando4"
    }, {
      name: "teste2",
      description: "testando2"
    }, {
      name: "teste3",
      description: "testando3"
    }, {
      name: "teste4",
      description: "testando4"
    }]


        this.tableParams = {
    TodoGeneral: null
  };
  this.tableParams['TodoGeneral'] = new NgTableParams({}, {
    dataset: $scope.fsck,
  });

 $scope.test = function() {
    $scope.fsck[0].name = "mais non";
 }
}

NgTableParams 实例化中使用 getData 而不是 dataset。 然后您可以通过 tableName.reload() 更新您的 table 并调用 getData 方法。

此处唯一不同的是分页行为,您可能希望在文档中重新阅读。

这是工作 fiddle:http://jsfiddle.net/vqxscmsu/17/

var demo = this;
// ...
demo.tableParams['TodoGeneral'] = new NgTableParams({}, {
    getData: function(){
       return $scope.fsck;
     }
});

$scope.test = function() {
    $scope.fsck[0].name = "mais non";
    demo.tableParams.TodoGeneral.reload();
}