我使用以下代码实现了离子手风琴效果。它按预期工作正常,但我想默认打开第一支手风琴。
<ion-item class="item-stable"
ng-click="toggleGroup(0)"
ng-class="{active: isGroupShown(0)}">
<i class="icon" ng-class="isGroupShown(0) ? 'ion-minus' : 'ion-plus'"></i>
Permanant Address
</ion-item>
<div class="item-accordion" ng-show="isGroupShown(0)">
---------
</div>
<ion-item class="item-stable"
ng-click="toggleGroup(1)"
ng-class="{active: isGroupShown(1)}">
<i class="icon" ng-class="isGroupShown(1) ? 'ion-minus' : 'ion-plus'"></i>
Temporary Address
</ion-item>
<div class="item-accordion" ng-show="isGroupShown(1)">
---------
</div>
$scope.toggleGroup = function(group) {
if ($scope.isGroupShown(group)) {
$scope.shownGroup = null;
} else {
$scope.shownGroup = group;
}
};
$scope.isGroupShown = function(group) {
return $scope.shownGroup === group;
};
答案 0 :(得分:4)
只需在for循环的末尾添加此行:
$scope.shownGroup = $scope.groups[0];