2013-05-09 52 views
0

ng-repeat綁定集合過濾布爾使用標籤,我有一個ng重複,顯示一個集合過濾布爾使用製表符(收藏項),當我更新了過濾器不會重新應用的集合。我有:當我更新集合過濾器不重新應用

全部商品|收藏夾

  • 項1
  • 項目2
  • 項目3

當第一負載(使用JSON)從所述服務器收集,凸片工作得很好,並過濾收集。當您點擊某個項目時,我會更新該項目的收藏夾屬性,但過濾器不會更新,如果您在標籤中單擊,似乎數據不會更新。

代碼:

HTML:

<button class="btn" ng-model="section" value="all-items" ng-click="filterCriteria={}; activate('all-items')" ng-class="{disabled: products.length == 0, active: section == 'all-items'}">All items ({{products.length}})</button> 

<button class="btn" ng-model="section" value="favourites" ng-click="activate('favourites'); filterCriteria.Favourite = true;" ng-class="{disabled: (products | filter: {Favourite:true}).length < 0, active: section == 'favourites'}">Favourites</button> 

<!-- List of products --> 
<ul> 
    <li ng-repeat="product in products | filter: filterCriteria"> 
     <button class="btn" type="button" ng-click="favouriteClick(product)">Favourite</button> 
     <p>{{product.description}}</p> 
    </li> 
</ul> 

控制器

app.controller('ProductListCtrl', ['$scope', '$http', function ($scope, $http, $filter)  { 

    $http.get('/Products').success(function (data) { 
     $scope.products = data; 
    }); 

    $scope.filterCriteria = {}; 
    $scope.section = "all-items"; 

    $scope.activate = function (option) { 
     $scope.section = option; 
    }; 

    $scope.favouriteClick = function (product) { 

     product.favourite = !product.favourite; 

     // Sync with back-end 
     $http({ 
      method: 'POST', 
      url: '/SetFavourite', 
      data: 'name=' + product.Sku + '&value=' + product.favourite, 
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' } 
     }); 
    }; 
} ]); 

任何反饋不勝感激。 感謝

編輯

我創建了一個撥弄解決方案http://jsfiddle.net/njrHm/

+0

加載後'$ scope.products'看起來像什麼? – Langdon 2013-05-09 19:00:23

回答

0

這是一個外殼的問題。你有:

ng-click="activate('favourites'); filterCriteria.Favourite = true;" 

...然後你有:

product.favourite = !product.favourite; 

我猜想你要改變你的ngClick使用小寫favourite