Skip to content

Instantly share code, notes, and snippets.

@quickstep25
Created July 9, 2015 09:37
Show Gist options
  • Save quickstep25/a9e97795cb3a4389bf28 to your computer and use it in GitHub Desktop.
Save quickstep25/a9e97795cb3a4389bf28 to your computer and use it in GitHub Desktop.
Passing Parent Model to Child such that the child can reference parent values
var Item = function(name, parent) {
this.name = ko.observable(name);
this.isSelected = ko.computed(function() {
return this === parent.selectedItem();
}, this);
};
var ViewModel = function() {
this.selectedItem = ko.observable();
this.items = ko.observableArray([
new Item("one", this),
new Item("two", this),
new Item("three", this)
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment