通过按特定键角

时间:2018-01-07 14:49:40

标签: arrays angularjs checkbox filter angularjs-ng-repeat

我有这种对象数组:

 $scope.instList= [
      {date:'06-11-2015', 25Code : '0', state: 'true', id : 21},
      {date:'15-11-2015', 25Code : '1', state: 'true', id : 22},
      {date:'24-11-2015', 25Code : '1', state: 'true', id : 23},
      {date:'28-12-2015', 25Code : '1, state: 'true', id : 24},
      {date:'28-12-2016', 25Code : '0', state: 'false', id : 241},
      {date:'28-12-2017', 25Code : '0', state: 'false',  id : 2432},
      {date:'28-11-2015', 25Code : '1', state: 'false',id : 2342},
      {date:'28-11-2017', 25Code : '0', state: 'false', id : 2443},
      {date:'28-11-2016', 25Code : '1', state: 'false', id : 2243},
      {date:'28-11-2016', 25Code : '0', state: 'false',id : 2242},


 ];

我有重复显示我的所有数据,我的问题是如何使用ng-repeat创建此块之外的复选框,以及过滤和显示仅包含的更新数据的目的:25Code:&# 39; 1&#39 ;. 例如:

<input type="checkbox" ng-model="">
<ul>
  <li class="active" ng-repeat="row in instList">
  <div ng-bind="row.date"></div>
  </li>
  <li class="active" ng-repeat="row in instList">
  <div ng-bind="row.date">
  </div>
  </li> 

1 个答案:

答案 0 :(得分:0)

您可以使用过滤器按ng-repeat内的属性进行过滤,首先指定复选框的ng-true-value和ng-false值

<input type="checkbox" ng-model="filterCode" ng-true-value="1" ng-false-value="">

并在ng-repeat

中按25code过滤
<input type="checkbox" ng-model="filterCode" ng-true-value="1" ng-false-value="">
<ul>
  <li class="active" ng-repeat="row in instList |filter: { Code: filterCode}">
  <div ng-bind="row.date"></div>
  </li>
</ul>

<强> Demo