我使用AngularJS和数据表连同服务器端脚本通过AJAX来获取数据。
我的控制器是这样的:
var currentJobId = $stateParams.jobId;
var selectedJobId = $rootScope.currentJob;
if (currentJobId !== selectedJobId) {
$rootScope.currentJob=$stateParams.jobId;
var data = {
id: $stateParams.jobId
}
$http.post('http://localhost/angular/scripts/getJob.php', data).success(function (thedata) {
$scope.job = thedata.information;
$scope.jobNotes = thedata.notes;
$scope.jobMaterialUsage = thedata.materialUsage;
$scope.jobItems = thedata.jobItems;
$scope.jobSubcontractorCosts = thedata.subcontractorCosts;
$scope.jobBondMiscCosts = thedata.bondMiscCosts;
$scope.jobEmployeeTime = thedata.employeeTime;
});
}
一个例子表如下所示:
Employee NameTotal Hours
{{time.name}}{{time.total_minutes}}Employee NameTotal Hours因此,它基本上是看是否作业ID发生了变化,如果有变化,就使Ajax调用新作业信息 - 如果它并没有改变它什么都不做。 我的问题是,我的表被初始化的数据加载之前的数据表时,我打刷新。 从这个页面离开并回到它正确初始化数据表,而是通过URL去时,直接到页面或刷新它只是把数据在表格的上方,同时仍保持了“在表中没有可用的数据”和无数据表功能工作。