Javascript AngularJS-复选框从选中对象获取id
如您所见,我在模态中有一个对象列表,右侧有一个复选框。现在我想点击复选框,只选中一项。现在,当我点击一个复选框时,所有东西都会被选中。但最重要的是,我想归档以下内容: 我想点击复选框,并获得id或被选中的团队。谢谢你的帮助 这是我的模态:Javascript AngularJS-复选框从选中对象获取id,javascript,angularjs,angularjs-ng-model,Javascript,Angularjs,Angularjs Ng Model,如您所见,我在模态中有一个对象列表,右侧有一个复选框。现在我想点击复选框,只选中一项。现在,当我点击一个复选框时,所有东西都会被选中。但最重要的是,我想归档以下内容: 我想点击复选框,并获得id或被选中的团队。谢谢你的帮助 这是我的模态: <div class="col-md-12"> <ul class="list-group"> <li ng-repeat="team in teams" class="list-group-item"&g
<div class="col-md-12">
<ul class="list-group">
<li ng-repeat="team in teams" class="list-group-item">{{ team.allUserTeamName + " - " + team.allUserTeam }}
<label ng-repeat="(feature,enabled) in features">
<input type="checkbox" ng-model="features[feature]"/>
</label>
</li>
</ul>
</div>
<div class="modal-footer">
<div class="col-md-12">
<div class="row pad-team-selection-view">
<button class="btn btn-info"
ng-click="createGameplanWithSelectedMembers(team)">Spielplan
erstellen
</button>
</div>
</div>
</div>
{{features.value}}
app.controller('modalCreateGameplanController', ['$scope', '$timeout', '$http', '$firebaseArray', '$firebaseObject', function($scope, $timeout, $http, $firebaseObject, $firebaseArray) {
$scope.selectUsers = 'Users';
$scope.$on('modal', function(event, args) {
var ref = firebase.database().ref("users");
var teams = $firebaseObject(ref);
$scope.features = {
value: false
};
teams.$loaded().then(function() {
$scope.teams = [];
angular.forEach(teams, function(key) {
$scope.teams.push({
allUserTeamName: key.firstname,
allUserTeam: key.team
});
});
});
});
}]);
现在,当我点击一个复选框时,所有东西都会被选中
每个团队的模型需要不同:
<div class="col-md-12">
<ul class="list-group">
<li ng-repeat="team in teams" class="list-group-item">
{{ team.allUserTeamName + " - " + team.allUserTeam }}
<label ng-repeat="(key,value) in features">
<input type="checkbox"
ng-model="team.key"
ng-change="onCheckboxChange(team, key)"
/>
</label>
</li>
</ul>
</div>
这可能是您的错误。复选框all select将不是默认行为,除非以这种方式定义,或者您的范围模型对所有这些框都是相同的。您在寻找吗?@Vega Yes类似的东西…@Sagar如何实现它?您必须在浏览器控制台中检查生成的html并进行验证。谢谢,这解决了一个问题:)如果复选框为true或false,我现在该怎么做?
$scope.onCheckboxChange = function(team, key) {
console.log("Change for "+ team.allUserTeamName);
console.log(key +" changed to "+ team.key);
};