How to get the values of an ng-repeat radio and checkbox nested in ng-repeat? The code is as follows:
<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 " ng-model="nums.option_id" >
<label for="{{nums.option_id}}">22222</label>
</p>
<p ng-repeat="nums in item.ques_item_options" ng-if="item.ques_item_type==2">
<input type="checkbox" " class="magic-radio " ng-model="nums.option_id" >
<label for="{{nums.option_id}}">22222</label>
</p>
</li>
</ul>
How to get input[radio] and input[checkbox] in double-layer ng-repeat? How should ng-model be set?
扔个三星炸死你2017-06-13 09:24:52
<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}}
怪我咯2017-06-13 09:24:52
I’ve been doing this recently too. If you have any problem with the value, please explain it in detail. You can also bind the model