2016-06-28 131 views
0

我做錯了什麼,因爲我無法實現我需要的結果。在單獨的過濾器中有多個複選框的角度過濾器

我的JSON數據看起來像這樣

[{ 
type_id: 1, 
brand_id: 0, 
name: 'Title', 
description: 'Description', 
img: 'url' 
},...] 

所以我需要通過type_idbrand_id 過濾數據它不是一個複雜的任務,但卡住了很多,我會很高興從你我任何幫助目前無法處理。

這就是我的觀點。我有兩個過濾器,它們是由ng-repeat 和ng-repeat生成的,用於我需要按類型和品牌過濾器進行過濾的設備。

// filter 1 
<div class="filters"> 
    <h3 class="filters__title">Choose by type</h3> 
    <div class="swiper-container"> 
     <div class="swiper-arrow-prev"></div> 
     <div class="swiper-arrow-next"></div> 
     <div class="swiper-overflow"> 
     <div class="swiper-wrapper filter" data-id="type"> 
      <div class="swiper-slide filter__checkbox" ng-repeat="item in types"> 
       <input type="checkbox" name="{{item.id}}" id="filter-{{item.id}}" ng-model="item.id" ng-checked="item.id"> 
       <label for="filter-{{item.id}}"> 
       <span>{{item.type}}</span> 
       </label> 
      </div> 
      <!-- /item --> 
     </div> 
     <!-- /filter --> 
     </div> 
    </div> 
</div> 
<!-- /filters --> 

// filter 2 
<div class="filters"> 
    <h3 class="filters__title">Choose by brand</h3> 
    <div class="swiper-container"> 
     <div class="swiper-arrow-prev"></div> 
     <div class="swiper-arrow-next"></div> 
     <div class="swiper-overflow"> 
     <div class="swiper-wrapper filter" data-id="brands"> 
      <div class="swiper-slide filter__checkbox" ng-repeat="brand in brands"> 
       <input type="checkbox" name="{{brand.id}}" id="brand-{{brand.id}}" ng-model="brand.id"> 
       <label for="brand-{{brand.id}}"> 
       <img ng-src="{{brand.img}}" alt=""> 
       <span>{{brand.name}}</span> 
       </label> 
      </div> 
      <!-- /item --> 
     </div> 
     <!-- /filter --> 
     </div> 
     <!-- /swiper-overflow --> 
    </div> 
    <!-- /swiper-container --> 
</div> 
<!-- /filters --> 


<div class="card" ng-repeat="device in devices"> 
    <div class="card__wrap"> 
     <figure> 
     <img ng-src="{{device.img}}" alt=""> 
     </figure> 
     <!-- /img --> 
     <h3 class="card__title">{{device.model}}</h3> 
    </div> 
</div> 
<!-- /card --> 


angular.module('app', []).controller('mainCtrl', ['$scope', 'dataJSON', '_', function($scope, dataJSON, _) { 
      $scope.filterContainer = []; 

      // get Data 
      dataJSON.getPromise().then(function(data) { 
       $scope.brands = data.brands; 
       $scope.devices = data.devices; 
       $scope.types = data.device_types; 

       return data.devices; 
      }).then(function(data) { 

      }) 
     }]) 
+0

不知道這個問題的答案是令人信服我學習角的js –

+0

沒有得到什麼你究竟在尋找.. –

回答

0

您可以使用下面的代碼過濾

// let take two input 
<input ng-model="type_id_model"><input ng-model="brand_id_model"> 


// filter 1 
    ng-repeat="item in types | filter:{type_id : type_id_model}" 
// filter 2 
    ng-repeat="brand in brands | filter:{brand_id : brand_id_model}" 
+0

不知道這是否我想要什麼 我需要過濾設備,而不是過濾器類型和品牌。 還需要注意的是,它的複選框,所以它可能不止一種類型和品牌 但謝謝你的帖子 –

+0

Json的devide對象有type_id,brand_id嗎? –

+0

是的,它的type_id和brand_id –