javascript - how to update filter function in ng-repeat -
there problem, when click 1 of tab
<div class="segmented-control"> <a href="#" ng-click="click(1)" ng-class="class" class="control-item ">near</a> <a href="#" ng-click="click(2)" ng-class="class" class="control-item ">often</a> <a href="#" ng-click="click(0)" ng-class="class" class="control-item ">all</a> </div>
then
<li class="table-view-cell media" ng-repeat="shop in shops | filter: func | orderby:'bysort'">
could update "filter: func". , angularjs here
$scope.shops =[{..,near:ture,often:flase},{..,near:false,often:true}]; $scope.click = function(e) {..}
then can't put
look @ snippet:
angular.module('myapp', []) .controller('mycontroller', function($scope){ $scope.locations = [ { name: 'near', near: true, often: null }, { name: 'often', near: null, often: true }, { name: 'all', near: null, often: null }]; $scope.currentlocation = null; $scope.shops = [ { name: "first", near: true, often: false }, { name: "second", near: true, often: true }, { name: "third", near: false, often: true }, { name: "fourth", near: false, often: false } ]; $scope.setcurrentlocation = function(location){ $scope.currentlocation = location; }; $scope.shopfilter = function(shop){ var location = $scope.currentlocation; if(location == null) return true; return (location.near === null && location.often == null) || location.near === shop.near || location.often === shop.often; }; });
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myapp"> <div ng-controller="mycontroller" > <div> <div class="btn-group"> <button class="btn btn-default" ng-repeat="loc in locations" ng-click="setcurrentlocation(loc)">{{loc.name}}</button> </div> </div> <ul class="list-group col-sm-4"> <li class="list-group-item" ng-repeat="shop in shops | filter:shopfilter">{{shop.name}}</li> </ul> </div> </div>
Comments
Post a Comment