这是jsfiddle Reference
我第一次创作小提琴不知道为什么说myApp没有定义请改变一样。
<div ng-app="myApp">
<div ng-controller="myCtrlr">
<div class="userAssign" ng-repeat="user in children">
<br>
<span class="main-header-cardion">
<a role="button" class="collapsed" data-toggle="collapse" data-parent="#accordion" href="" ng-click="swapUser(user.user_id);" aria-expanded="true" aria-controls="collapseTwo">
<span ng-if="user.type == '2'">{{user.first_name}}</span>
<span ng-if="user.type == '3'">{{user.name}}</span>
</a>
</span>
<section class="accordion1" ng-show="state && parentUser.user_id == user.user_id">
{{user.age}}
{{user.height}}
</section>
</div>
</div>
</div>
angular.module('myApp',[])
.controller('myCtrlr', ['$scope',function($scope){
$scope.children = [
{
"first_name" : "Alfreds",
"last_name" : "Futterkiste",
"name" : "Alfreds Futterkiste",
"age" : "50",
"height" : "5",
"type" : "2",
"user_id" : "1"
},{
"first_name" : "John",
"last_name" : "Futterkiste",
"name" : "John Futterkiste",
"age" : "50",
"height" : "5",
"type" : "2",
"user_id" : "2"
},{
"first_name" : "Jimmy",
"last_name" : "Futterkiste",
"name" : "Jimmy Futterkiste",
"age" : "50",
"height" : "5",
"type" : "3",
"user_id" : "3"
},{
"first_name" : "Shekh",
"last_name" : "Futterkiste",
"name" : "Shekh Futterkiste",
"age" : "50",
"height" : "5",
"type" : "3",
"user_id" : "4"
}
];
$scope.last_element = $scope.children[$scope.children.length - 1];
$scope.parentUser = $scope.last_element;
$scope.swapUser = function swapUser(user_id)
{
$scope.children.filter(function(item){
if(item.user_id == user_id)
{
$scope.state = !$scope.state;
$scope.currentSetUser = user_id;
return $scope.parentUser = item;
}
});
}
}]);
预期:最初打开第一个锚值,然后当我们点击休息时,它应立即打开并关闭休息。
目前当我点击一个时会发生什么,当我点击链接旁边显示详细信息时隐藏第一个值,然后点击它显示值。
提前致谢