I have a player class and viewmodel
class Player
constructor: ->
@boat = ko.observable null
class Boat
constructor: (@id) ->
class ViewModel
player: ko.observable
in html
<div data-bind="if: player">
<div data-bind="template: {name: 't_me', data: player}"></div>
</div>
<script type="text/html" id="t_me">
<span>player boat
<span data-bind="if: boat()">
<b data-bind="text: boat().id"></b>
</span>
</span>
</script>
now in script i try to set boat to plyer
vm = new ViewMode()
ko.applyBindings vm
vm.player new Player()
vm.player.boat new Boat(1)
And I can’t make View react on this changes any ideas?
The only problem I see with your code is lack of parens on the
vm.playerobservable. (assuming thatvm = new ViewMode()is a typo)I believe the last line should be:
vm.player().boat new Boat(1)