Rumah > Soal Jawab > teks badan
Bagaimana untuk mendapatkan nilai radio ng-repeat dan kotak semak bersarang dalam ng-repeat Kodnya adalah seperti berikut:
<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>
Bagaimana untuk mendapatkan input[radio] dan input[kotak semak] dalam dua lapisan ng-repeat Bagaimanakah model ng harus ditetapkan?
扔个三星炸死你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
Saya juga telah melakukan ini baru-baru ini Jika anda mempunyai sebarang masalah dengan nilai, sila jelaskan secara terperinci Anda juga boleh mengikat model