优化搜索angularjs显示所有结果onload

时间:2014-06-13 15:08:23

标签: javascript angularjs

目标:

我想第一次加载所有巡演。但我不希望第一次选中所有复选框。

HTML code:

<div ng-repeat="style in styles">
      <input type="checkbox" ng-model="style.selected"> {{style.name}}
    </div>
    <div ng-repeat="tour in tours | filter: hasStyle">Name: {{tour.Tourname}} | Styles: {{tour.style}}</div>

Angular JS:

angular.module('myApp', [])
.controller('MyController', function($scope){
  $scope.styles = [{"name":"walking"},{"name":"food"},{"name":"culture"}];
  $scope.tours = [{"Tourname":"sky walk","style":"walking "},{"Tourname":"Accra markets","style":"food,walking"}];

  $scope.hasStyle = function(item){
    return $scope.styles.some(function(style){
      if(style.selected && item.style.indexOf(style.name) > -1) {
        return true;
      }
    })
  }
});

这是DEMO

0 个答案:

没有答案