仅更新更新AngularJS上的元素

时间:2015-04-20 09:56:37

标签: javascript angularjs

我有一个对象数组,可以根据返回API的数据进行更改,我只想更改已更改的元素而不重新加载整个ng-repeat

编辑(试着解释一下): 当数据更改AngularJS重新创建整个DOM删除所有元素并再次创建它时,我想保留未更改的元素并重新加载新元素。

以下是我展示数据的方式:

   <div class="row" id="main">
      <div class="col-xs-12 col-sm-6 col-md-3 col-lg-2 block animate" ng-repeat="build in build | limitTo:totalDisplayed | orderBy:'lastBuildDetails.startDate' : true track by build._id" ng-class="{'running': project.running ,'block-green': build._status ==='SUCCESS','block-red': build._status==='FAILURE'}" id="{{build._id}}" progressive-loading="">
        <div class="title-container animate">
          <p>{{build._buildTypeId}}</p> 
        </div>
        <div class="update-container animate col-xs-12">
          <time class="time">{{build.buildDate | date : 'dd.MM.yyyy H:mm:s'}} </time>
        </div>
      </div>
    </div>

这是一个示例数组:

     $scope.build = [
    { _id:1, _status:'SUCCESS', lastBuildDetails:{startDate:1}, _buildTypeId:1},
    { _id:2, _status:'SUCCESS', lastBuildDetails:{startDate:1}, _buildTypeId:2},
    { _id:3, _status:'SUCCESS', lastBuildDetails:{startDate:9}, _buildTypeId:3},
    { _id:4, _status:'SUCCESS', lastBuildDetails:{startDate:8}, _buildTypeId:4},
    { _id:5, _status:'SUCCESS', lastBuildDetails:{startDate:1}, _buildTypeId:5},
    { _id:6, _status:'SUCCESS', lastBuildDetails:{startDate:6}, _buildTypeId:6},
    { _id:7, _status:'SUCCESS', lastBuildDetails:{startDate:5}, _buildTypeId:7},
    { _id:8, _status:'SUCCESS', lastBuildDetails:{startDate:4}, _buildTypeId:8},
    { _id:9, _status:'SUCCESS', lastBuildDetails:{startDate:3}, _buildTypeId:9},
    { _id:10, _status:'SUCCESS', lastBuildDetails:{startDate:2}, _buildTypeId:10}
    ];

此处以及来自API的不同元素响应的示例:

     $scope.build = [
    { _id:11, _status:'SUCCESS', lastBuildDetails:{startDate:1}, _buildTypeId:11},
    { _id:2, _status:'FAILED', lastBuildDetails:{startDate:1}, _buildTypeId:2},
    { _id:13, _status:'SUCCESS', lastBuildDetails:{startDate:9}, _buildTypeId:13},
    { _id:4, _status:'SUCCESS', lastBuildDetails:{startDate:8}, _buildTypeId:4},
    { _id:15, _status:'FAILED', lastBuildDetails:{startDate:1}, _buildTypeId:15},
    { _id:6, _status:'SUCCESS', lastBuildDetails:{startDate:6}, _buildTypeId:6},
    { _id:17, _status:'SUCCESS', lastBuildDetails:{startDate:5}, _buildTypeId:17},
    { _id:8, _status:'FAILED', lastBuildDetails:{startDate:4}, _buildTypeId:8},
    { _id:19, _status:'SUCCESS', lastBuildDetails:{startDate:3}, _buildTypeId:19},
    { _id:20, _status:'FAILED', lastBuildDetails:{startDate:2}, _buildTypeId:10}
    ];

对不起我的英语,如果您不了解我或需要更多信息,请告诉我。

0 个答案:

没有答案