angularjs无线电组唯一名称生成

时间:2015-09-23 19:03:31

标签: javascript angularjs

一切都不顺利。 ng-repeat工作正常。它是从json创建选项,但问题是每个收音机都有相同的名称。因为一次只能选择一个无线电。如何为每个广播组生成唯一的名称扩展名。

这是plnkr。 http://plnkr.co/edit/Vze4y6QEerhiTPX7sEZz?p=preview

var app = angular.module('q', []);

app.controller('aCtrl', function($scope) {
    this.sets = set;
});// Fin aCtrl

var set = 
[
    { 
        "qus" :"what is your name?",
        "option1" : {"ans" : "Alex", "cor":"false"},
        "option2" : {"ans" : "Hervy", "cor":"false"},
        "option3" : {"ans" : "Rico", "cor":"true"},
        "option4" : {"ans" : "Tom", "cor":"false"},
    },
    { 
        "qus" :"what is your brother's name?",
        "option1" : {"ans" : "Alex", "cor":"false"},
        "option2" : {"ans" : "Hervy", "cor":"true"},
        "option3" : {"ans" : "Rico", "cor":"false"},
        "option4" : {"ans" : "Tom", "cor":"false"},
    },
]

1 个答案:

答案 0 :(得分:1)

您可以生成包含迭代索引的名称。例如:

<li class="list-group-item">
    <input type="radio" name="op + {{$index}}" ng-value="{{qs.option2.cor}}" ng-model="nv1">
    <span class="up">{{qs.option1.ans}}</span>
</li>

因此,群组名称将为op0op1等。

演示: http://plnkr.co/edit/sRUa1qhmMlHD8GXGF6PO?p=preview