Created
July 9, 2015 09:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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