扫码关注官方订阅号
ng-repeat中嵌套一个ng-repeat radio和checkbox怎么取值? 代码如下:
22222 22222
22222
怎么在双层ng-repeat情况取到input[radio]和input[checkbox]? ng-model应该怎么设置?
<ul class="options_box" > <li ng-repeat="item in ques.ques_items"> <p ng-repeat="nums in item.ques_item_options" ng-if="item.ques_item_type==1"> <input type="radio" class="magic-radio " id="{{item.ques_item_id}}{{nums.option_id}}" name="{{item.ques_item_id}}" value="{{nums.option_id}}" ng-model="result[item.ques_item_id]"> <label for="{{item.ques_item_id}}{{nums.option_id}}" ng-bind="nums.option_label"></label> </p> <p ng-repeat="nums in item.ques_item_options" ng-if="item.ques_item_type==2"> <input type="checkbox" class="magic-radio" id="{{item.ques_item_id}}{{nums.option_id}}" ng-model="result[item.ques_item_id][nums.option_id]"> <label for="{{item.ques_item_id}}{{nums.option_id}}" ng-bind="nums.option_label"></label> </p> </li> </ul>
$scope.result = {}; $scope.ques = { ques_items: [ { ques_item_type: 1, ques_item_id: 1, //问题id ques_item_options: [ { option_id: 'A', option_label: '测试1' }, { option_id: 'B', option_label: '测试2' }, { option_id: 'C', option_label: '测试3' }, { option_id: 'D', option_label: '测试4' } ] }, { ques_item_type: 2, ques_item_id: 2, ques_item_options: [ { option_id: 'A', option_label: '测试1' }, { option_id: 'B', option_label: '测试2' }, { option_id: 'C', option_label: '测试3' }, { option_id: 'D', option_label: '测试4' } ] }, { ques_item_type: 2, ques_item_id: 3, ques_item_options: [ { option_id: 'A', option_label: '测试1' }, { option_id: 'B', option_label: '测试2' }, { option_id: 'C', option_label: '测试3' }, { option_id: 'D', option_label: '测试4' } ] } ] }
result: {"1":"D","2":{"A":true,"B":true,"C":true,"D":true},"3":{"D":false}}
最近也在做这个 你取值有什么问题 具体说明一下 你绑定model也是可以的
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
最近也在做这个 你取值有什么问题 具体说明一下 你绑定model也是可以的