var MenuModel = function() {
var preselected = "Profile";
this.name = ko.observable().subscribeTo("nickName");
this.sections = ["Profile", "Notifications","Users","Projects"];
this.selectedSection = ko.observable(preselected).publishOn("section");
};
var ProfileModel = function() {
//publish updates to the nick name
this.nickName = ko.observable("Ryan").publishOn("nickName");
//apply a filter to turn the value that we receive into a boolean
this.visible = ko.observable().subscribeTo("section", function(newValue) {
return newValue === "Profile";
});
//subscribe and publish on the "email" topic to keep this observable in sync between view models
this.emailAddress = ko.observable("[email protected]").syncWith("email");
};
var NotificationsModel = function() {
this.visible = ko.observable(false);
//as an alternative, use a direct subscription on the topic to update the observable
ko.postbox.subscribe("section", function(newValue) {
this.visible(newValue === "Notifications");
}, this);
//subscribe and publish on the "email" topic to keep this observable in sync between view models
this.emailAddress = ko.observable("[email protected]").syncWith("email");
this.sendNewsLetter = ko.observable(false).syncWith("sendNewsLetter");
};
var User = function(data){
var self = this;
self.ID = data.ID;
self.name = ko.observable(data.name);
};
var UserModel = function(){
this.visible = ko.observable(false);
ko.postbox.subscribe("section",function(newValue) {
this.visible(newValue === "Users");
}, this);
this.sendNewsLetter = ko.observable(false).syncWith("sendNewsLetter");
// projects
this.Projects = ko.observableArray().syncWith("myProjects");
this.selectedProject = ko.observable().syncWith("selectedProjects");
// users
this.Users = ko.observableArray().syncWith("myUsers");
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.