存在HTML數據綁定設置器的問題。我希望它設置爲模型(exerciseCategories)間隔值。 如果我綁定到模型的間隔,它是正確的值,但不可觀察。 如果我將它綁定到$ parent.intervals,它是來自viewModel的默認值(1),但它是可觀察的。 我想都:)。我究竟做錯了什麼? 像這樣的工作,但顯示[目標對象]:KnockoutJS數據綁定設置器
<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);
};
你是如何獲取數據到您的視圖模型? – 2013-03-04 10:51:59
你將不得不提供更多的代碼。我缺少與綁定的for:綁定和視圖模型的表標記。我認爲你在混合觀看模型。 – nickvane 2013-03-04 10:59:12
這只是摘錄。整體幾乎相同http://jsfiddle.net/rniemeyer/adNuR/ – kayz1 2013-03-04 11:57:39