2017-11-18 110 views
0

我有一個表中顯示數據的列表,我在angularjs中工作。並且我獲得了演出數據的成功。並在我的數據一個提交有nama 追隨者計數。所以在頁面加載表是顯示和在後臺我的一個進程正在運行的獲得追隨者形式instagram api.so在這個過程中我已經settimeout爲1 - 1追隨者採取並採取5秒機智,然後在第二次追隨者採取。該類型的一個一個追隨者採取了5秒的時間間隔之後,所以我顯示追隨者在表中計數,所以這裏我需要顯示估計你的追隨者下載時間的時間。如何計算估計時間並使用角度js顯示在表格中?

對於前=>我有16個追隨者,並在後臺1追隨者採取機智和5秒後,所以我的16個追隨者在下載後的時間段。爲前。 1分鐘,1小時,每日1次,等...

這裏是我的表HTML =>

<table> 
    <tr> 
     <th>Target UserName</th> 
     <th>Followers</th> 
     <th>Status</th> 
    <th>Estimated time</th>   
    </tr> 
    <tr ng-repeat="r in Result"> 
     <td>{{r.target_username}}</td> 
     <td>{{r.followres_count}}</td> 
     <td>{{r.Flage ? "Done" : "running"}}</td> 
     <td>{{r.followres_count * 5 }}</td> // here i have try like this but not get propare answer.   
    </tr> 
</table> 

這裏我的數據看起來像=>

TARGET  FOLLOWERS STATUS ESTIMATED TIME 
abc   16  Done    80 
t   3000  Done   15000 
+0

你在這個'r.followres_count'中得到的總數是多少? – Durga

+0

@Durga是的,我是總跟隨計數進入r.followres_count – Edit

+0

你想顯示'80'爲'1min 20sec'? – Durga

回答

2

var myApp = angular.module('myApp',[]); 
 

 
//myApp.directive('myDirective', function() {}); 
 
//myApp.factory('myService', function() {}); 
 

 
function MyCtrl($scope) { 
 
    $scope.name = 'Superhero'; 
 
    $scope.setValue = function(){ 
 
    var x = 11111150000; 
 
    var time = moment.duration(x); 
 
    var day = time.days(); 
 
    var hr = time.hours(); 
 
    var min = time.minutes(); 
 
    var sec = time.seconds(); 
 
    var y = (day ? day +' days ' : '') + (hr ? hr +' hours ' : '') + (min ? min +' min ':'') + (sec ? sec +' sec':''); 
 
    return y; 
 
    } 
 
}
<script src="https://code.angularjs.org/angular-1.0.1.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.2/moment.js"></script> 
 
<body ng-app="myApp"> 
 
    <div ng-controller="MyCtrl"> 
 
    <table> 
 
     <tr> 
 
      <td ng-bind="setValue()"></td> 
 
     </tr> 
 
    </table> 
 
    </div> 
 
</body>

使用moment.duration獲取時間格式,如果您知道具體的時間時間。

+0

我的追隨者總數是16那麼在後臺1乘1追隨者間隔5秒之間下載,所以在哪個時間段這16個追隨者下載完成?所以你的解決方案如何通過我的計數和乘以5秒? – Edit

+0

@編輯通過追隨者總功能和你的情況'x = folowersTotal * 5 * 1000;' – Durga

+0

我的表在ng-repeat所以我怎麼能稱這個功能爲每個原料? – Edit