2017-03-17 66 views
0

我在做一个表格,其中有两个过滤器复选框。首先是“360” - 当你点击表格时只显示360,同样的作品过滤“2D” - 当你在表格中点击它时只显示2D。我在JS中这样做,但我想要做的是当你点击“360”,在表中只显示360,但当你点击“2D”在这个时候“360”没有选中。我尝试通过单选按钮来做到这一点,但我的CSS复选框不起作用。第二次点击后取消选中第一个过滤器

JSON “DATAS”:

[{"type":"2D"},{"type":"2D"},{"type":"360"},{"type":"2D"},{"type":"360"},{"type":"2D"},{"type":"360"},{"type":"2D"},{"type":"360"},{"type":"2D"}] 

我的HTML:

 <div class="form-group" style="display:block;width:40px;padding-left: 5px;float:left;height:70px;"> 
      <input type="checkbox" id='checkbox-360' class='tags-checkbox sr-only' value="" ng-model="type2.type360"><label for='checkbox-360'> 
      <i class='glyphicon glyphicon-unchecked' style="color:darkgrey;width:2px;font-size:25px;"></i> 
      <i class='glyphicon glyphicon-check' style="color:cornflowerblue;width:2px;font-size:25px;"></i> 
      <h4><small>360</small></h4> 
     </label> 
     </div> 
     <div class="form-group" style="display:block;width:40px;padding-left:5px;float:left;height:70px;"> 
      <input type="checkbox" id='checkbox-20' class='tags-checkbox sr-only' value="" ng-model="type1.type2D"><label for='checkbox-20'> 
      <i class='glyphicon glyphicon-unchecked' style="color:darkgrey;width:2px;font-size:25px;"></i> 
      <i class='glyphicon glyphicon-check' style="color:cornflowerblue;width:2px;font-size:25px;"></i> 
      <h4><small>2D</small></h4> 
     </label> 
     </div> 

    <tr ng-repeat="data in datas |TypeFilter360:type2.type360 | TypeFilter2D:type1.type2D> 
        <td>{{data.type}}</td> 
</tr> 

CSS:

input[type='checkbox'].tags-checkbox:checked + label > i:first-of-type, 
input[type='checkbox'].tags-checkbox + label > i:last-of-type{ 
    display: none; 
} 
input[type='checkbox'].tags-checkbox:checked + label > i:last-of-type{ 
    display: inline-block; 
} 

JS

var app = angular.module('app', []); 
    app.service('service', function($http, $q){ 
     this.getDatas = function() { 
      var datas = $http.get('datas.json', {cache: false}); 
      return $q.all({datas}); 
     }; 
    }); 
    app.controller('FirstCtrl', function($scope, service, $http) { 

      var promise = service.getDatas(); 
      promise.then(function (data) { 
       $scope.datas = data.datas.data; 
       console.log($scope.datas); 
      }) 
}) 
    .filter('TypeFilter2D', function(){ 
      return function(data, type2D){ 
       if (!type2D) return data; 
       var filtered2D = []; 
       angular.forEach(data, function(item){ 
        if(type2D == false) { 
         filtered2D.push(item); 
        } 
        else if(type2D == true && item.type == "2D"){ 
         filtered2D.push(item); 
        } 
       }); 

       return filtered2D; 
      }; 
     }) 
     .filter('TypeFilter360', function(){ 
      return function(data, type360){ 
       if (!type360) return data; 
       var filtered360 = []; 
       angular.forEach(data, function(item){ 
        if(type360 == false) { 
         filtered360.push(item); 
        } 
        else if(type360 == true && item.type == "360"){ 
         filtered360.push(item); 
        } 
       }); 

       return filtered360; 
      }; 
     }) 

那么我想要做什么 - 当点击“360”过滤器,然后我点击“2D”过滤器“360”应该取消选中。 感谢您提前给出答案!

回答