本文介绍了如何根据带有MVC的angulerjs中的值设置复选框列表中的选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想设置选择的几个爱好,如'写','足球'在复选框列表中如何做到这一点?我的代码如下, 角度控制器 $ scope.Hobbies = []; $ scope.Hobbies.push(' Cricket'); $ scope.Hobbies.push(' Reading'); $ scope.Hobbies.push(' Writing'); $ scope.Hobbies.push(' Sleeping'); $ scope.Hobbies.push(' Running'); $ scope.Hobbies.push(' Football'); $ scope.Hobbies.push(' Programming'); $ scope.selected = {}; $ scope.GetSelected = function (){ console .log(' select arry ....'); $ .each($ scope.selected, function (value,checked){ console .log(value + ' - + checked); }); }; $ scope.SetSelected = function (){ // ??? }; 我的.cshtml代码 < div > 兴趣爱好 < label ng-repeat = 爱好中的爱好者 > < input type = 复选框 checklist-model = 爱好 ng-model = selected [hobbie] checklist-value = {{hobbie}} > {{hobbie } < / label > < / div > < a href = javascript:; data-ng-click = SetSelected(); > 设置所选 < / a > 我的尝试: i想要设置选择的几个爱好,如'写','足球'在复选框列表中如何做到这一点?? 解决方案 scope.Hobbies = [ ]; scope.Hobbies.push(' Cricket' ); scope.Hobbies.push(' 阅读' ); i want to set as selected few hobbies like 'Writing','Football' in checkbox list how to do this?? my code as below,angular controller$scope.Hobbies = [];$scope.Hobbies.push('Cricket');$scope.Hobbies.push('Reading');$scope.Hobbies.push('Writing');$scope.Hobbies.push('Sleeping');$scope.Hobbies.push('Running');$scope.Hobbies.push('Football');$scope.Hobbies.push('Programming');$scope.selected = {};$scope.GetSelected = function () { console.log('selected arry....'); $.each($scope.selected, function (value,checked) { console.log(value + '-' + checked); });}; $scope.SetSelected = function () { //???};my .cshtml code<div>Hobbies <label ng-repeat="hobbie in Hobbies"> <input type="checkbox" checklist-model="Hobbies" ng-model="selected[hobbie]" checklist-value="{{hobbie}}">{{hobbie}} </label> </div><a href="javascript:;" data-ng-click="SetSelected();">Set Selected</a>What I have tried:i want to set as selected few hobbies like 'Writing','Football' in checkbox list how to do this?? 解决方案 scope.Hobbies = [];scope.Hobbies.push('Cricket');scope.Hobbies.push('Reading'); 这篇关于如何根据带有MVC的angulerjs中的值设置复选框列表中的选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!