我正在從數據庫中加載數據到一個表與Angualar js的HTML。我也使用間隔,以便每10秒鐘重新加載表以獲取剛剛由其他用戶輸入的新數據。從數據庫加載數據不閃爍角Js
問題: 該表在每次重新加載時閃爍。使頁面看起來很有趣,就像它有一個小故障。
什麼在尋找: 有沒有一種辦法可以讓新的數據只是從表的頂部滑動,併成爲頭號其餘的重新調整它的下面併成爲數二,三等等上。我被弄得相信角的js就是爲什麼我選擇了它,而不是用我平時的AJAX
角碼
var supDetails = angular.module("supDetails", ['datatables']);
supDetails.controller('supportController', function($scope, $http, $interval) {
$scope.names = [];
$scope.isFirst = true;
$scope.loadData = function() {
var httpRequest = $http({
method: 'GET',
url: 'anfil.php?ins=sup'
}).success(function(data, status) {
console.log('loading..');
$scope.names = data;
if(!$scope.isFirst){
angular.forEach(data,function(key,val){
$scope.names[key] = data[key];
});
}
$scope.isFirst = false;
});
};
$scope.loadData();
// Function to replicate setInterval using $timeout service.
$interval(function() {
$scope.loadData();
}, 10000);
});
我的HTML神奇的原因
<!-- /.col -->
<div class="col-md-9" ng-app = "supDetails" ng-controller="supportController">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Messages</h3>
<!-- /.box-tools -->
<div class="box-tools pull-right">
<div class="has-feedback">
<button type="button" ng-click="loadData()" class="btn btn-default btn-sm"><i class="fa fa-refresh"></i></button>
</div>
</div>
</div>
<!-- /.box-header -->
<div class="box-body no-padding">
<div class="mailbox-messages">
<table datatable="ng" class="table table-hover table-striped">
<thead>
<tr>
<th>Stat</th>
<th>Name</th>
<th>Problem</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in names">
<td class="mailbox-star"><a href="#"><i class="fa fa-circle text-blue"></i></a></td>
<td class="mailbox-name"><a href="read-mail.html">{{x.user_id}}</a></td>
<td class="mailbox-subject"><b>{{x.ticket_title}}</b> - {{x.subject}}
</td>
<td class="mailbox-date">{{x.ticket_open_date}}</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Stat</th>
<th>Name</th>
<th>Problem</th>
<th>Time</th>
</tr>
</tfoot>
</table>
<!-- /.table -->
</div>
<!-- /.mail-box-messages -->
</div>
<!-- /.box-body -->
</div>
<!-- /. box -->
</div>
<!-- /.col -->
感謝您使我的天,我幾乎SO瀏覽時笑。 「我被認爲相信Angular Js是神奇的」。是的,令人驚訝的是,這不是魔術。你可以向谷歌提問誰寫的;) – dirkk