所以我使用NGTable在我的页面上显示数据,数据存储在数组中并通过数据集参数但是当我以编程方式更改数组中数据的值时,更改会正确显示在表格 BUT 当我转到第二页并再次转到第一页时,表格会显示旧数据。
这是一个说明我的问题的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";
}
}
答案 0 :(得分:1)
在getData
实例化中使用dataset
代替NgTableParams
。
然后,您可以通过tableName.reload()
更新您的表格,并调用getData
方法。
这里唯一不同的是您可能想要在文档中重读的分页行为。
这是工作小提琴: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();
}