页面加载时角度过滤器和开口手风琴的问题

时间:2015-07-03 22:52:30

标签: javascript angularjs twitter-bootstrap angular-filters

由于添加角度滤波器,手风琴在页面加载时不会打开。我想这与代码is-open="group.isOpen"group在该实例中不再有效有关吗?导致代码现在使用key, value?我做错了什么?

Here's a plunker问题。

**编辑:((并且,根据评论中的要求,在添加角度滤镜之前,页面加载时手风琴开放的here's a plunker))。

这里是html:

<div ng-controller="AccordionDemoCtrl">
    <accordion close-others="oneAtATime">

      <accordion-group is-open="group.isOpen" ng-repeat="(key, value) in groups | groupBy: 'title'">
        <accordion-heading><i class="glyphicon-plus"></i> {{ key }}
          <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': group.isOpen, 'glyphicon-chevron-right': !group.isOpen}"></i>
        </accordion-heading>
       <p ng-repeat="group in value"> {{ group.content }}</p>
        <ul>
      <li ng-repeat="group in value">

        {{ group.list }}
      </li>
    </ul>

      </accordion-group>

    </accordion>
  </div>

这里是js:

angular.module('app', ['ui.bootstrap','ngSanitize','angular.filter']);
angular.module('app').controller('AccordionDemoCtrl', function ($scope) {
  $scope.oneAtATime = true;

  $scope.groups = [
    {
      title: 'title 1',
      content: 'content 1',
      isOpen: true,
      list: 'item0a'
    },
    {
      title: 'title 2',
      content: 'Content 2',
      list: 'item0b' 
    },
    {
      title: 'title 3',
      content: 'Content 3',
      list: 'item0c' 
    },
    {
      title: 'title 4',
      content: 'content 4',
      list: 'item0d' 
    },
    {
      title: 'title 5',
      content: 'content 5',
      list: 'item0e' 
    },
    {
      title: 'title 1',
      list: 'item1a'
    },
    {
      title: 'title 1',
      list: 'item2a'
    },
    {
      title: 'title 1',
      list: 'item3a'
    },
    {
      title: 'title 2',
      list: 'item1b'
    },
    {
      title: 'title 2',
      list: 'item2b'
    },
    {
      title: 'title 3',
      list: 'item1c'
    },
    {
      title: 'title 3',
      list: 'item2c'
    },    
    {
      title: 'title 4',
      list: 'item1d'
    },
    {
      title: 'title 5',
      list: 'item1e'
    }
  ];
});

1 个答案:

答案 0 :(得分:1)

我不知道你的对象结构是否有特定原因,但是

{
  title: 'title 1',
  content: 'content 1',
  isOpen: true,
  list: ['item1a',
    'item2a',
    'item3a']
}

对我来说更有意义。现在你基本上不需要更改实际视图,除了添加列表。

    <ul>
      <li ng-repeat="item in group.list">
        {{ item }}
      </li>
    </ul>

http://plnkr.co/edit/LBNQ2ukERMEzH3gKQ4M6?p=preview