HTML 数据绑定设置器有问题。我希望它设置为模型(exerciseCategories)间隔值。如果我绑定到模型的间隔,它是正确的值,但不可观察。如果我将它绑定到 $parent.intervals 它是 viewModel 的默认值 (1) 但它是可观察的。我想要两个:)。我究竟做错了什么?像这样的东西确实有效,但显示 [object Object]:
<td data-bind='with: exercise'>
<input data-bind='value: $parent.intervals(intervals)' />
</td>
What I've got is - HTML
...
<td>
<select data-bind='options: exerciseCategories , optionsText: "category", optionsCaption: "Izberite...", value: exerciseType'></select>
</td>
<td data-bind="with: exerciseType">
<select data-bind='options: exercises, optionsText: "title", optionsCaption: "Izberite...", value: $parent.exercise'></select>
</td>
<td data-bind='with: exercise'>
<input data-bind='value: $parent.intervals' />
</td>
...
JavaScript
var exerciseCategories = [
{
exercises: [{
title: 'Aerobic exercise #1',
intervals: 2
}],
category: 'Aerobics'
}];
var Exercise = function () {
var self = this;
self.exerciseType = ko.observable();
self.exercise = ko.observable();
self.intervals = ko.observable(1);
};