我正在使用ngTable来显示数据。第一次单击按钮时,它会进行AJAX调用并显示数据。在此之后,点击某些按钮后,它会进行AJAX调用,它会获取新数据,但不会在表格中更新。
这是我的控制器代码:
d3.selectAll(".nv-point").on("click", function (hourly_datapoint) {
console.log("hourly_datapoint",hourly_datapoint);
$http.post('/api/hostlevel', hourly_datapoint).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
console.log(data);
console.log(status);
var data = data[0].data[0][hourly_datapoint.time];
console.log(data);
$scope.$watch('data', function () {
$scope.tableParams.settings().$scope = $scope;
$scope.tableParams.reload();
});
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log(data);
console.log(status);
});
});
}
这是观看代码:
<div>
<br/>
<br/>
<table ng-table="tableParams" class="table" ng-show="$data.length >0">
<tr ng-repeat="hostlevel in $data">
<td data-title="'Messages Received'">{{hostlevel["in"]}}</td>
<td data-title="'Messages Processed'">{{hostlevel["out"]}}</td>
</tr>
</table>
</div>
如何动态更新表格内容?有人可以帮帮我吗?