gpt4 book ai didi

javascript - 如何使用 AngularJS 填充复选框值列表?

转载 作者:行者123 更新时间:2023-12-03 01:25:25 25 4
gpt4 key购买 nike

我正在尝试在服务器端使用 Angular JS 构建一个测验应用程序,因为我有两种类型的选择:

  1. 一个问题有多个选项(输入复选框)“数据类型”:3,
  2. 单一选项对于一个问题。 (输入 radio ) “dataType”:2,

我正在尝试填充多个checkbox问题的存储答案,在这种情况下storedAnswer是一个数组,而storedAnswer是一个整数值输入 radio

注意: storedAnswer 数组包含 option.questionChoiceValue

我的问题是如何填充数组值作为多选(复选框)问题的检查:

这是我的 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>

我有一个像这样的对象:

[
{
"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"
}
]

最佳答案

我相信您的 radio 应该使用 ng-checked 而不是 ng-model。像这样:

<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);" />

关于javascript - 如何使用 AngularJS 填充复选框值列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51573515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com