[英]How to populate list of checkbox values with AngularJS?
I am trying to build a quiz application in angular js with serverside for that i have 2 type of choices: 我正在尝试使用服务器端在angular js中构建测验应用程序,因为我有2种选择:
(input-checkbox)
. (input-checkbox)
。 "dataType": 3,
(input-radio)
"dataType": 2,
(input-radio)
"dataType": 2,
I am trying to populate stored answer for multiple checkbox
questions in this case storedAnswer
is an array, whereas storedAnswer
is an integer value for input radio
我正在尝试填充多个
checkbox
问题的存储答案,在这种情况下, storedAnswer
是一个数组,而storedAnswer
是input radio
的整数值
Note: storedAnswer
array contains the option.questionChoiceValue
's 注意:
storedAnswer
数组包含option.questionChoiceValue
的
My question is how can i populate array value as checked for multiple choice ( checkbox
) question: 我的问题是我如何填充数组值作为多选(
checkbox
)问题的检查:
This is my HTML code: 这是我的HTML代码:
<div ng-repeat="question in data.questionData">
<span name="multiSelectCheckBox" ng-if="question.dataType == 3">
<div ng-repeat="option in question.choices " class="">
<label for="mul_{{option.questionChoiceValue}}_ques{{option.questionId}}">
<span ng-repeat="stAns in question.storedAnswer"
ng-if="stAns == option.questionChoiceValue">
<input id="mul_{{option.questionChoiceValue}}_ques{{option.questionId}}"
type="checkbox"
ng-model="question.storedAnswer"
ng-change="onSelect(question, option);" />
{{option.questionChoiceText}}
</span>
</label>
</div>
</span>
<span name="multiSelectRadio" ng-if="question.dataType == 2">
<div ng-repeat="option in question.choices " class="">
<label for="sin_{{option.questionChoiceValue}}_ques{{option.questionId}}">
<input type="radio" id="sin_{{option.questionChoiceValue}}_ques{{option.questionId}}"
ng-model="question.storedAnswer"
value="{{option.questionChoiceValue | number}}"
name="que_ques{{option.questionId}}"
ng-change="onSelect(question, option);" />
{{option.questionChoiceText}}
</label>
</div>
</span>
</div>
I have an object like this: 我有一个这样的对象:
[
{
"marked": "false",
"questionId": "7d00a35ddb6313004f3bdde748961969",
"helpText": "",
"answered": "true",
"storedAnswer": [
1,
5
],
"questionSno": 1,
"dataType": 3,
"choices": [
{
"questionId": "7d00a35ddb6313004f3bdde748961969",
"questionChoiceValue": 5,
"questionChoiceText": "Float, long double"
},
{
"questionId": "7d00a35ddb6313004f3bdde748961969",
"questionChoiceValue": 4,
"questionChoiceText": "Float"
},
{
"questionId": "7d00a35ddb6313004f3bdde748961969",
"questionChoiceValue": 3,
"questionChoiceText": "float, double, long double"
},
{
"questionId": "7d00a35ddb6313004f3bdde748961969",
"questionChoiceValue": 2,
"questionChoiceText": "long double, short int"
},
{
"questionId": "7d00a35ddb6313004f3bdde748961969",
"questionChoiceValue": 1,
"questionChoiceText": "short int, double, long int, float"
}
],
"questionText": "In C, what are the various types of real data type (floating point data type)?",
"selected": "false"
},
{
"marked": "false",
"questionId": "93e5c5e5db6713004f3bdde748961957",
"helpText": "",
"answered": "false",
"storedAnswer": 1,
"questionSno": 3,
"dataType": 2,
"choices": [
{
"questionId": "93e5c5e5db6713004f3bdde748961957",
"questionChoiceValue": 3,
"questionChoiceText": "May be"
},
{
"questionId": "93e5c5e5db6713004f3bdde748961957",
"questionChoiceValue": 2,
"questionChoiceText": "False"
},
{
"questionId": "93e5c5e5db6713004f3bdde748961957",
"questionChoiceValue": 1,
"questionChoiceText": "True"
}
],
"questionText": "A macro can execute faster than a function.",
"selected": "false"
}
]
I believe you should be using ng-checked instead of ng-model for your radio. 我相信您应该在收音机中使用ng-checked而不是ng-model。 Like this:
像这样:
<input type="radio" id="sin_{{option.questionChoiceValue}}_ques{{option.questionId}}"
ng-checked="question.storedAnswer"
value="{{option.questionChoiceValue | number}}"
name="que_ques{{option.questionId}}"
ng-change="onSelect(question, option);" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.