Javascript 具有JSON数据和粘性可折叠行的动态表

Javascript 具有JSON数据和粘性可折叠行的动态表,javascript,angularjs,json,Javascript,Angularjs,Json,我将Angular 1与一个工厂一起使用,该工厂为JSON数据轮询REST API。这个JSON然后用ng repeat start填充一个表,使用ng repeat end我有一个隐藏的表行,其中包含额外的数据 对我来说似乎很平常 但问题是,当我每5秒或10秒轮询一次API时,如何在下次轮询时保持可折叠表行的打开状态 在大多数情况下,数据不会更改,因此没有理由关闭可折叠行,但它会在我的工厂进行的每次轮询时关闭 下面是其中一个表的示例 <table class="pure-table

我将Angular 1与一个工厂一起使用,该工厂为JSON数据轮询REST API。这个JSON然后用ng repeat start填充一个表,使用ng repeat end我有一个隐藏的表行,其中包含额外的数据

对我来说似乎很平常

但问题是,当我每5秒或10秒轮询一次API时,如何在下次轮询时保持可折叠表行的打开状态

在大多数情况下,数据不会更改,因此没有理由关闭可折叠行,但它会在我的工厂进行的每次轮询时关闭

下面是其中一个表的示例

  <table class="pure-table pure-table-horizontal alerts-table" id="alert-nagios-host-table">
    <thead>
      <tr>
        <th>Hostname</th>
        <th>Status</th>
        <th>Output</th>
      </tr>
    </thead>
    <tbody>
      <tr class="parent-row" ng-repeat-start="alert in alerts" ng-click="child.expanded = !child.expanded">
        <td>{{alert.hostname}}</td>
        <td ng-class="{3:'grayBg', 2:'redBg', 1:'yellowBg', 0:'greenBg'}[alert.state]">{{alert.status}}</td>
        <td>{{alert.output}}</td>
      </tr>
      <tr class="child-row" ng-init="child.expanded = false" ng-show="child.expanded" ng-repeat-end>
        <td colspan=4>Duration: {{alert.duration}}</td>
      </tr>
    </tbody>
  </table>
mondashApp.factory('AlertsPoller', function ($http, $timeout) {
    var data = {resp: {}, count: 0};
    var count=0;

    var poller = function (url, success) {
        count++;
        $http.get(url).then(function (responseData) {
            data.count = count;
            data.resp = responseData.data;
            success(data);
            $timeout(function () {poller(url, success);}, 5000);
        });
    };

    return {
        poller: poller
    };
});

mondashApp.controller('nagiosHostAlertsCtrl', function nagiosHostAlertsCtrl($scope, AlertsPoller) {
    AlertsPoller.poller('/alert/nagios/host', function(response) {
        $scope.alerts = response.resp.alerts;
    });
});