我有一个播放器类和视图模型
class Player
constructor: ->
@boat = ko.observable null
class Boat
constructor: (@id) ->
class ViewModel
player: ko.observable
在 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>
现在在脚本中,我尝试将船设置为 plyer
vm = new ViewMode()
ko.applyBindings vm
vm.player new Player()
vm.player.boat new Boat(1)
而且我不能让 View 对这种变化做出反应,有什么想法吗?