gpt4 book ai didi

javascript - AngularJS:Ngtable 重新加载到旧数据

转载 作者:行者123 更新时间:2023-11-29 23:22:51 27 4
gpt4 key购买 nike

所以我使用 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() 更新你的表,它会调用 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();
}

关于javascript - AngularJS:Ngtable 重新加载到旧数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50131544/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com