2017-08-25 106 views
0

我想我的程序过滤器,但我不知道如何做到这一点..谷歌只给我那些搜索字段过滤器或复选框的名称..我没有得到它..迄今..角度过滤器的复选框,与复选框

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

app.controller('BackendCtrl', function($scope, $http){ 

     $scope.informations = [ 
      { 
       id: 123, 
       text: "first object", 
       checkbox: 1, 
      }, 
      { 
       id: 222, 
       text: "second object", 
       checkbox: 1, 
      }, 
      { 
       id: 303, 
       text: "third object", 
       checkbox: 1, 
      }, 
      { 
       id: 412, 
       text: "fourth object", 
       checkbox: 0, 
      }, 
      { 
       id: 500, 
       text: "fifth object", 
       checkbox: 0, 
      }, 
      { 
       id: 666, 
       text: "sixth object", 
       checkbox: 1, 
      }, 

     ]; 
    }); 

这是我的角度数据!

 <html> 
<head> 
    <title>Survey</title> 

    <meta http-equiv="content-type" content="text/html; charset=utf-8"> 
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /> 
    <meta http-equiv="Pragma" content="no-cache" /> 
    <meta http-equiv="Expires" content="0" /> 
</head> 
<body ng-app="surveyApp" ng-controller="BackendCtrl"> 

<div style="width: 150px; height: 40px; border:1px solid;"> 

    <input type="checkbox"/> All objects 

</div> 

<div> 
    <table border="1" style="margin: 0 auto;" ng-controller="BackendCtrl"> 
     <tr ng-repeat="item in informations"> 
      <td>{{item.id}}</td> 
      <td>{{item.text}}</td> 
      <td><input type="checkbox" ng-model="item.checkbox" ng-true-value="1" ng-false-value="0"/>cool</td> 
     </tr> 
    </table> 
</div> 

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script> 
<script src="app.js"></script> 

</body> 
</html> 

第一个复选框应该是我的item.checkbox ..如果它的真实,所有数字应该给,如果它的虚假只有“不酷”的对象过滤器.. greez 请帮助我

+0

那么......哪里出了问题?任何错误可能? –

+0

有没有错误..我需要在那里的过滤器,theres没有 –

回答

0

我认为你可以做这样的:

在你的控制器:

$scope.filter = {showall: True} 

在模板:

<div style="width: 150px; height: 40px; border:1px solid;"> 

    <input type="checkbox" ng-model="filter.showall"/> All objects 

</div> 

<div> 
    <table border="1" style="margin: 0 auto;" ng-controller="BackendCtrl"> 
     <tr ng-repeat="item in informations" 
      ng-if="filter.showall || item.is_not_cool"> 
      <td>{{item.id}}</td> 
      <td>{{item.text}}</td> 
      <td><input type="checkbox" ng-model="item.checkbox" ng-true-value="1" ng-false-value="0"/>cool</td> 
     </tr> 
    </table> 
</div> 

我不知道什么是"not cool" objects如你所说的话,但你可以修改条件item.is_not_cool你想要什么。