Angularjs $http调用后无法刷新ng表。
在我的SPA中,我有一个activate函数,它有一个promise getNodes() getNodes()调用数据库以获取“Node”列表,我正在用它生成一个分组的ng表Angularjs $http调用后无法刷新ng表。,angularjs,ngtable,Angularjs,Ngtable,在我的SPA中,我有一个activate函数,它有一个promise getNodes() getNodes()调用数据库以获取“Node”列表,我正在用它生成一个分组的ng表 function getNodes() { return datacontext.getNodes().then(function (response) { $scope.data = response.data; $scope.$watch("qu
function getNodes() {
return datacontext.getNodes().then(function (response) {
$scope.data = response.data;
$scope.$watch("query", function () {
$scope.tableParams.reload();
});
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
sorting: {
name: 'asc'
}
}, {
groupBy: function (item) {
return item.NodeGroup.Name;
},
total: $scope.data,
getData: function ($defer, params) {
var filteredData = new Array();
var func = (function () {
$scope.data.forEach(function (node) {
var is = !!((node.Name.toLowerCase().indexOf($scope.query || '') !== -1) || (node.IP.toLowerCase().indexOf($scope.query || '') !== -1) || (node.NodeGroup.Name.toLowerCase().indexOf($scope.query || '') !== -1));
if (is) {
filteredData.push(node);
}
});
})();
var orderedData = params.sorting() ?
$filter('orderBy')(filteredData, params.orderBy()) :
filteredData;
$scope.tableParams.total(orderedData.length);//this is also nto working for me.
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
},
$scope: $scope
});
});
}
发生的情况是,当id添加一个节点时,它不会更新我的表。如果我刷新页面,我可以看到新添加的节点。但我希望我的表在添加后很快刷新
添加节点后,我再次调用activate,但它不起作用
function addNode(node) {
return datacontext.addNode(node).then(function (response) {
activate();
});
经过一些研究,我在下面加了一行
$scope.tableParams.total(orderedData.length);
这对我也不起作用。请帮忙 我只需更新我的添加和更新小说,就可以修复我的添加和更新 在add的情况下,在成功调用add服务器后,我将新添加的对象推入$scope.data,然后调用 $scope.tableParams.reload() 在update的情况下,我通过Id查找要更新的对象,并在成功调用update后用更新的对象替换它,然后调用$scope.tableParams.reload() 但我的问题是,这是刷新ng表的最好方法还是我遗漏了什么
function addNode(node) {
return datacontext.addNode(node).then(function (response) {
$scope.data.push(node);
$scope.tableParams.reload();
//activate();
});
}
及
function addNode(node) {
return datacontext.addNode(node).then(function (response) {
$scope.data.push(node);
$scope.tableParams.reload();
//activate();
});
}
function updateNode(node) {
return datacontext.updateNode(node).then(function (response) {
$scope.data.forEach(function (old) {
var is = old.Id == node.Id;
if (is) {
var index = $scope.data.indexOf(old);
$scope.data[index] = node;
}
});
$scope.tableParams.reload();
});
}