我正在寻找使用路由器应用程序在角度js中创建调查系统的解决方案。我想过使用.js文件来存储问题,例如:
var question = [[
"What's your programming language of choose ?",
"Java",
"C/C++",
"Python",
"PHP",
"Lisp",
[
"Another question",
"option",
"option",
"option"
]];
现在在app angular js:
.state('question1', {
url: '/question1;',
templateUrl: 'questions/question1.php',
controller: function($scope) {
$scope.title= question[0][0],
$scope.question = [question[0][1],question[0][2][0][3];
}
})
在这里,我想做一个循环来查找问题数组中的所有问题。 最好的方法是什么?
答案 0 :(得分:1)
你可以使用这样的东西
var question = [
{
"question":"What's your programming language of choose ?",
"answers":{
"answer_1":"Java",
"answer_2":"C/C++",
"answer_3":"Python",
"answer_4":"PHP",
"answer_5":"Lisp",
}
},{
"question":"Another question",
"answers":{
"answer_1":"option",
"answer_2":"option",
"answer_3":"option",
"answer_4":"option",
"answer_5":"option",
}
}];
$scope.question = question;
和你的html中的例子
<div ng-repeat="ques in question">
{{ques.question}}
<div ng-repeat="answ in ques.answers">
<label>{{answ}}:<input type="checkbox"/></label>
</div>