1

I have a viewmodel setup that is as follows:

<div id='stuff'>

<div id='i_need_this'>
<input type='checkbox' data-bind="checked: enabled" />
</div>

</div>

<script>
var vm = new vm();
ko.applyBindings(vm, $("#stuff").get(0));
var i_need_this_vm = new i_n_t();
ko.applyBindings(i_need_this_vm, $("#i_need_this").get(0));
</script>

I have one viewmodel that is bound to the parent div of "stuff" but I want the i_need_this viewmodel to be bound to the i_need_this div. When I apply this binding though I am getting an error that "Uncaught Error: Unable to parse bindings. Message: ReferenceError: enabled is not defined;" Is this related to how my viewmodels are arranged, and if so is there a way around it?

Thanks!

4

1 回答 1

2

Unfortunately, you can not bind a parent and child element to different viewmodels like that. See this link for a possible work-around. http://www.knockmeout.net/2012/05/quick-tip-skip-binding.html

于 2013-07-10T16:59:17.537 回答