我堅持與執行以下操作:獲取嵌套數組取決於下拉選擇,使之可觀察
的邏輯如下:取決於用戶選擇的形式,獲得與此相關的表格所有部分。例如:如果用戶選擇名稱爲「T-01」的表格,那麼章節數組必須填寫與該表格相關的所有章節。並且每個部分必須是可觀察的以便進一步計算。
這裏是我的表單模型:
function Form(name, title, max, total, sections) {
this.Name = ko.observable(name);
this.Title = ko.observable(title);
this.MAX = ko.observable(max);
this.Total = ko.observable(total);
this.Sections = ko.observableArray(sections);
this.addSection = function() {
this.Sections.push(new Section());
}.bind(this);
}
var FormOptions = ko.observableArray(['T-01', 'T-02', 'T-03']);
而且這裏的部分型號:
function Section(section, criteria, is, cs, nc, fc, totalInitialScores, totalFinalScores) {
this.Section = ko.observable(section);
this.Criteria = ko.observable(criteria);
this.IS = ko.observable(is);
this.CS = ko.observable(cs);
this.NC = ko.observable(nc);
this.FC = ko.observable(fc);
this.TotalInitialScores = ko.observable(totalInitialScores);
this.TotalFinalScores = ko.observable(totalFinalScores);
}
我有一個根級別的幾個型號,但我不包括在這裏,不知道如果需要的話。