【发布时间】:2014-09-30 16:35:43
【问题描述】:
*这是我的 html 文件,我想在其中重复章节,这是一个看起来像的数组 我的代码仅将选定的复选框(索引值)绑定为真。但我需要在提交时检索整个章节列表及其 ID。 无法弄清楚如何在嵌套循环上迭代它 *
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<span ng-repeat="chapter in chapters">
<label><input type="checkbox" name="checkbox" value="{{chapter}} ng-model="escConfigForm.chapters[$index]" >{{chapter.name}}</label><br>
</span>
<input type="submit" id="save" value="Save" />
$scope.chapters = chapterService.getChapters($scope.isbn);
$scope.submit = function(escConfigForm) {
var postData = {
content_items: JSON.stringify({
"@context" : [],
"@graph" : [ {
"@type" : "ContentItemPlacement",
"placementOf" : {
"@type" : "LtiLink",
"text" : escConfigForm.examName,
"mediaType" : "application/vnd.ims.lti.v1.launch+json",
"title" : "Exam Study Center",
"custom" : {
"dueDate" : escConfigForm.examDueDate,
"targetScore" : escConfigForm.examTargetScore,
"chapters" : escConfigForm.chapters
},
"activityType" : "other",
"activityRefId" : $scope.escId
}
} ]
}),
data: $scope.data
};
postForm($scope.postUrl, postData);
var configData = {
"activityRefId" : $scope.escId,
"dueDate" : escConfigForm.examDueDate,
"targetScore" : escConfigForm.examTargetScore,
"chapters" : escConfigForm.chapters
};
console.log($scope.chapters);
JSON 文件:
[{"name":"Chapter 1: Negative Messages","id":"832115"},{"name":"Chapter 2: Physics","id":"832115"},... ]
【问题讨论】:
-
你在输入中的值在这段代码中没有关闭
-
您是否尝试将
<input>inside 嵌入<label>? -
能不能把控制器代码加到sn-p里
-
是的,标签由所有章节的复选框列表组成。当我检查并提交它们时,我需要将所选章节的列表连同他们的 ID 发送回后端。
-
这对你的 Q 来说是个好小提琴吗? jsfiddle.net/ruwk5r0v
标签: angularjs angularjs-ng-model