所以我使用 NGTable 在我的页面上显示数据,数据存储在数组中并通过数据集参数传递,但是当我以编程方式更改数组中数据的值时,更改会正确显示在表中,但是当我转到第二页并再次转到第一页时,表会显示旧数据。
这是一个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()
更新表,该 go 并调用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();
}