查看关于foreach和template绑定的文档将会有所帮助。
我会创建一个函数,可以重用n个主要部分。这个函数将有一个ko.observableArray
这将包含一个功能的部分。当你点击一个部分时,它会将该值设置为ko.observable
。
function MainSection() {
var self = this;
self.selectedSection = ko.observable();
self.sections = ko.observableArray(
[
new Section("Some Data"),
new Section("Some Data"),
new Section("Some Data"),
new Section("Some Data"),
new Section("Some Data"),
new Section("Some Data")
]);
self.selectSection = function(item) { //where item is a Section
self.selectedSection(item); //passed from the click binding
};
}