2014-06-23 228 views
0

嗨,我正在使用角度控制器和角度視圖。點擊按鈕打開AngularJS手風琴

在我看來,我有以下幾點:

<div ng-controller="AccordionDemoCtrl"> 
    <input type="search" class="form-control" ng-model="Filter" placeholder="Filter Search" /> 
    <accordion> 
     <accordion-group ng-repeat="group in groups" heading="{{group.title}}"> 
     {{group.content}} 
     </accordion-group>  
    </accordion> 
</div> 

然後在我的控制器我希望能夠做兩件事情:

  1. 打開手風琴完全用「是開」對各組
  2. 有點相關的一組「特寫他人=假」

我知道如何設置日在兩個方面作爲默認值,但我的問題是,我需要從我的控制器做到這一點,因爲我基本上使用ng模型來查看搜索框中的更改,並且用戶開始在此搜索框中輸入內容時我想要手風琴完全打開......並最終我將用戶._filter實際上做過濾..但第一步是觸發手風琴的開放

現在我的控制器看起來像這樣

$scope.$watch("Filter", function (newVal, oldVal, scope) { 
     console.log($scope.reportFilter); 

     if ($scope.Filter) 
     { 
      if ($scope.Filter.length == 0){ 
       // close the accordion 
       // show one at a time 

      } 

      else{ 

       // open the entire accordion 

      } 
     } 

回答

0

對於HTML:

<div ng-controller="AccordionDemoCtrl"> 
    <input type="search" class="form-control" ng-model="Filter" placeholder="Filter Search" /> 
    <accordion close-others="showOnlyOne"> 
     <accordion-group ng-repeat="group in groups" heading="{{group.title}}" is-open="group.isThisOpen"> 
     {{group.content}} 
     </accordion-group>  
    </accordion> 
</div> 

和一個控制器:

$scope.showOnlyOne=true; 
$scope.$watch("Filter", function (newVal, oldVal, scope) { 
     console.log($scope.reportFilter); 

     if ($scope.Filter) 
     { 
      if ($scope.Filter.length == 0){ 
       // close the accordion 
       // show one at a time 
       $scope.showOnlyOne=true; 
       $scope.groups.forEach(function(group){ 
        group.isThisOpen=false; 
       }); 
      } 

      else{ 
       $scope.showOnlyOne=false; 
       // open the entire accordion 
       $scope.groups.forEach(function(group){ 
        group.isThisOpen=true; 
       }); 
      } 
     } 
}; 

可能是會做的伎倆...

相關問題