angular-过滤器和页面加载时打开手风琴的问题
Issues with angular-filter and opening accordion on page load
自从添加 angular-过滤器后,手风琴在页面加载时不会打开。我想这与代码 is-open="group.isOpen"
和 group
在该实例中不再有效有关?导致代码现在使用 key, value
?我做错了什么?
Here's a plunker 的问题。
** 编辑:((并且,根据评论中的要求,here's a plunker 在添加 angular-filter 之前打开页面加载的手风琴))。
这是 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'
}
];
});
我不知道你的对象结构是否有特定的原因,但是像
{
title: 'title 1',
content: 'content 1',
isOpen: true,
list: ['item1a',
'item2a',
'item3a']
}
对我来说更有意义。现在你基本上根本不需要改变实际视图,除了添加列表。
<ul>
<li ng-repeat="item in group.list">
{{ item }}
</li>
</ul>
自从添加 angular-过滤器后,手风琴在页面加载时不会打开。我想这与代码 is-open="group.isOpen"
和 group
在该实例中不再有效有关?导致代码现在使用 key, value
?我做错了什么?
Here's a plunker 的问题。
** 编辑:((并且,根据评论中的要求,here's a plunker 在添加 angular-filter 之前打开页面加载的手风琴))。
这是 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'
}
];
});
我不知道你的对象结构是否有特定的原因,但是像
{
title: 'title 1',
content: 'content 1',
isOpen: true,
list: ['item1a',
'item2a',
'item3a']
}
对我来说更有意义。现在你基本上根本不需要改变实际视图,除了添加列表。
<ul>
<li ng-repeat="item in group.list">
{{ item }}
</li>
</ul>