angle.js - Wie erhalte ich in Angular die Werte von Radio und Checkbox unter der NG-Reprat-Doppelschichtschleife?
phpcn_u1582
phpcn_u1582 2017-06-13 09:22:52
0
2
1212

Wie erhalte ich die in ng-repeat verschachtelten Werte von ng-repeat radio und checkbox? Der Code lautet wie folgt:

<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>

Wie erhalte ich Eingabe[Radio] und Eingabe[Kontrollkästchen] im Double-Layer-NG-Repeat? Wie sollte das NG-Modell eingestellt werden?

phpcn_u1582
phpcn_u1582

Antworte allen(2)
扔个三星炸死你
    <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也是可以的

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage