簡體   English   中英

AngularJS Ng-repeat分組和過濾

[英]AngularJS Ng-repeat group by and filter

我有一個要訂購的來自Azure服務器日志的數組(單擊數組),這是請求:

$http({
      method: 'Get',
      headers: {
       'Host': 'api.applicationinsights.io',
       'x-api-key': 'xxxxxxxxxxxxxx'
       },

       url: 'https://api.applicationinsights.io/v1/apps/20exxxx-xxxx-xxxx-xxxx-cf8bc569d261/query?query=requests | where timestamp > datetime(2018-03-13) and timestamp <= datetime(2018-03-22) %2B 1d | where name contains "GetCode" | where name contains "9278"'
       })
         .success(function (data) {
          $scope.clicks = data.tables[0].rows;
          console.log($scope.clicks)
          })

這是我得到的數組(大約275.000行):

0:
Array(37)
0:"2018-03-22T08:37:02.982Z"
1:"|ypdKJH+nmLI=.aeeeecd8_"
2:null
3:"GET /content/GetCode/192.0/9278"
etc.
1:
Array(37)
0:"2018-03-22T08:37:04.877Z"
1:"|nynZFXWHS7g=.aeeeece2_"
2:null
3:"GET /content/GetCode/1773.0/9278"
etc.

現在在這種情況下,我在NG-Repet中僅使用[3],所以我做了以下工作:

<div ng-repeat="click in clicks">
    click: {{(click[3].split('GET /content/GetCode/')[1]).split('/9278')[0]}}
</div>

它給了我很好的時間清單

192.0
1773.0
198.5
112,0
32.8
3148.7
etc. x 100.000

我如何能夠每分鍾說一次如何將此列表分組,所以我將所有這些分組以30秒為一組。

像這樣:

  0- 30: 0
 31- 60: 1 (aka 32.8)
 61- 90: 0
 91-120: 1 (aka 112.0)
121-150: 0
151-180: 0
181-210: 2 (aka 192.0 & 198.5)
211-240: 0 etc. etc. you get the idea i guess.

我將如何做到這一點?

您需要為此使用JS:

  $scope.groupedArray = []
  var clicks = {
    1: [
      'asd', 'asdasd', 'GET /content/GetCode/192.0/9278'
    ],
    2: [
      'asd', 'asdasd', 'GET /content/GetCode/1773.0/9278'
    ]
  }
  var a = []
  for (var key in clicks) {
    a.push((clicks[key][2].split('GET /content/GetCode/')[1]).split('/9278')[0])
  }
  a = a.sort(function(a, b) {
    return a - b;
  })
  for(let i = 0; i<a.length; i++) {
    arrayIndex = parseInt(a[i]/30);
    $scope.groupedArray[arrayIndex] = ($scope.groupedArray[arrayIndex] == undefined) ? 1 : ($scope.groupedArray[arrayIndex] + 1);
  }
  for(let i = 0; i<$scope.groupedArray.length; i++) {
    $scope.groupedArray[i] = ($scope.groupedArray[i] == undefined) ? 0 : $scope.groupedArray[i]
  }

的HTML

<ul>
  <li ng-repeat="item in groupedArray">
    {{($index) * 30}} - {{($index + 1) * 30}} -> {{item}}
  </li>
</ul>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM