Javascript AngularJS:Ngtable重新加载到旧数据

Javascript AngularJS:Ngtable重新加载到旧数据,javascript,angularjs,ngtable,Javascript,Angularjs,Ngtable,所以我用NGTable在我的页面上显示数据,数据存储在数组中并通过dataset param传递,但当我以编程方式更改数组中数据的值时,更改将正确显示在表中,但当我转到第二页并再次转到第一页时,表将显示旧数据 下面是一个JSFIDLE,它说明了我的问题: 在NgTableParams实例化中使用getData而不是dataset。 然后,您可以通过tableName.reload()更新表,它将调用getData方法 这里唯一不同的是分页行为,您可能希望在文档中重读 这是工作小提琴: 由于您将数

所以我用NGTable在我的页面上显示数据,数据存储在数组中并通过dataset param传递,但当我以编程方式更改数组中数据的值时,更改将正确显示在表中,但当我转到第二页并再次转到第一页时,表将显示旧数据

下面是一个JSFIDLE,它说明了我的问题:


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

这里唯一不同的是分页行为,您可能希望在文档中重读

这是工作小提琴:


由于您将数据存储在
$scope
中,
$scope
将使用控制器中的init数据重新生成数据。如果要更改,可以存储到localStorage、Cookie或$rootScope。@TanDuong我曾尝试用$rootScope替换,但问题仍然存在。也许您可以尝试使用sessionStorage?我必须在getData()函数中添加一些内容才能使排序、筛选和分页正常工作。但是现在这个问题已经用这个解决方案解决了,谢谢!是的,我想起来了,但不记得该怎么办!
    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";
 }
}
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();
}