我有可观察阵列(等级)中的项目列表,在那里我从其他可观察阵列(课程)中选择了一些选项。单击更新按钮时如何获得所选课程? 我无法将“ value:course.id”更改为可观察的值,因为没有选择该值将无法填充课程。
HTML:
<!-- ko foreach: grades -->
<tr>
<td><input type="number" name="gradeValue" step=0.5 min=2.0 max=5.0 value=2.0
title="Value" data-bind="value: value" placeholder="Value"></td>
<td><select name="id" required data-bind="options: $parent.courses,
optionsText: function(i) { return i.name(); },
optionsValue: function(i) { return i.id(); },
optionsCaption: 'Choose course',
value: course.id ">
</select></td>
<td><input type="date" data-bind="value: date" required></td>
<td><input type="submit" value="Delete" data-bind="click: $root.deleteGrade.bind($data, $index())">
<input type="submit" value="Update" data-bind="click: $root.updateGrade.bind($data, $index())"></td>
</tr>
<!-- /ko -->
JS:
function ViewModel() {
// Data
var self = this;
self.courses = ko.observableArray([]);
self.grades = ko.observableArray([]);
self.updateGrade = function (index) { //do something }
}