我已经建立了一个手风琴列表,每个手风琴代表一组项目。 我使用ng-repeat来遍历组名,每个组都有一个复选框,表明它是否被选中。
该示例适用于单组手风琴,但是当我将手风琴放入ng-repeat时,根本无法选中复选框。
这是代码,每个组标题的主要复选框显然不起作用,我试着找出原因。
我的主要问题是:
1.如何激活Group1和Group2以及Group3的复选框,以便我可以正确选择它们。在目前情况下,我无法选择复选框(Group1,Group2和Group3)。
let mysockets = new parallel(socketList);
let mydata = mysockets.data;
mysockets.map(function(mydata){
if (mydata !== msg.socketId){
io.to(mydata).emit("new message", msg.Message)
}
}).then(function(){
console.log(mydata);
})

var app = angular.module('app',[]);
app.controller('mainCTRL',function($scope){
$('.collapse').collapse();
$scope.title="Hello World";
$scope.items1 = ['Group1','Group2','Group3']
})

.ui-checkbox {
display: none;
}
.ui-checkbox + label {
position: relative;
padding-left: 25px;
display: inline-block;
font-size: 14px;
}
.ui-checkbox + label:before {
background-color: #fff;
/**#fff*/
border: 1px solid #1279C6;
padding: 9px;
border-radius: 3px;
display: block;
position: absolute;
top: 0;
left: 0;
content: "";
}
.ui-checkbox:checked + label:before {
border: 1px solid #1279C6;
color: #99a1a7;
}
.ui-checkbox:checked + label:after {
content: '\2714';
font-size: 14px;
position: absolute;
top: 1px;
left: 4px;
color: #1279C6;
}

答案 0 :(得分:8)
问题是因为您的复选框嵌套在锚点内。只需更改:
<a data-toggle="collapse" data-parent="#accordion-{{$index}}"
data-target="#collapseOne-{{$index}}">
要:
<div data-toggle="collapse" data-parent="#accordion-{{$index}}"
data-target="#collapseOne-{{$index}}">
参见工作示例:
var app = angular.module('app',[]);
app.controller('mainCTRL',function($scope){
$('.collapse').collapse();
$scope.title="Hello World";
$scope.items1 = ['Group1','Group2','Group3']
})
&#13;
.ui-checkbox {
display: none;
}
.ui-checkbox + label {
position: relative;
padding-left: 25px;
display: inline-block;
font-size: 14px;
}
.ui-checkbox + label:before {
background-color: #fff;
/**#fff*/
border: 1px solid #1279C6;
padding: 9px;
border-radius: 3px;
display: block;
position: absolute;
top: 0;
left: 0;
content: "";
}
.ui-checkbox:checked + label:before {
border: 1px solid #1279C6;
color: #99a1a7;
}
.ui-checkbox:checked + label:after {
content: '\2714';
font-size: 14px;
position: absolute;
top: 1px;
left: 4px;
color: #1279C6;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js">
</script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div ng-app="app" ng-controller="mainCTRL">
<div ng-repeat="item in items1">
<div class="panel-group driving-license-settings" id="accordion-{{$index}}">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<div data-toggle="collapse" data-parent="#accordion-{{$index}}"
data-target="#collapseOne-{{$index}}">
<input type="checkbox" class="ui-checkbox" id="chk1-{{$index}}" value="">
<label for="chk1-{{$index}}">{{item}}</label>
</div>
</h4>
</div>
<div id="collapseOne-{{$index}}" class="panel-collapse collapse ">
<div class="panel-body">
<div class="driving-license-kind">
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-1" value="">
<label for="chk2-cb-{{item}}-1">A</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-2" value="">
<label for="chk2-cb-{{item}}-2">B</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-3" value="">
<label for="chk2-cb-{{item}}-3">C</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-4" value="">
<label for="chk2-cb-{{item}}-4">D</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-5" value="">
<label for="chk2-cb-{{item}}-5">E</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
&#13;
答案 1 :(得分:2)
问题是您指定的ID。使id唯一,复选框开始工作。这是固定的片段
var app = angular.module('app',[]);
app.controller('mainCTRL',function($scope){
$('.collapse').collapse();
$scope.title="Hello World";
$scope.items1 = ['Group1','Group2','Group3']
})
.ui-checkbox {
display: none;
}
.ui-checkbox + label {
position: relative;
padding-left: 25px;
display: inline-block;
font-size: 14px;
}
.ui-checkbox + label:before {
background-color: #fff;
/**#fff*/
border: 1px solid #1279C6;
padding: 9px;
border-radius: 3px;
display: block;
position: absolute;
top: 0;
left: 0;
content: "";
}
.ui-checkbox:checked + label:before {
border: 1px solid #1279C6;
color: #99a1a7;
}
.ui-checkbox:checked + label:after {
content: '\2714';
font-size: 14px;
position: absolute;
top: 1px;
left: 4px;
color: #1279C6;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js">
</script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div ng-app="app" ng-controller="mainCTRL">
<div ng-repeat="item in items1">
<div class="panel-group driving-license-settings" id="accordion-{{$index}}">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion-{{$index}}"
data-target="#collapseOne-{{$index}}">
<input type="checkbox" class="ui-checkbox" id="chk1-{{$index}}" value="">
<label for="chk1-{{$index}}">{{item}}</label>
</a>
</h4>
</div>
<div id="collapseOne-{{$index}}" class="panel-collapse collapse ">
<div class="panel-body">
<div class="driving-license-kind">
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-1" value="">
<label for="chk2-cb-{{item}}-1">A</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-2" value="">
<label for="chk2-cb-{{item}}-2">B</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-3" value="">
<label for="chk2-cb-{{item}}-3">C</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-4" value="">
<label for="chk2-cb-{{item}}-4">D</label>
</div>
<div class="checkbox">
<input type="checkbox" class="ui-checkbox" id="chk2-cb-{{item}}-5" value="">
<label for="chk2-cb-{{item}}-5">E</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>