可以多次绑定,但不能嵌套绑定
错误示例:
<div class="con_c" data-model="viewModel"> <div data-moel="lstViewModel"> </div> </div> <script type="text/javascript"> var vm = new ViewModel(); var vm2 = new CreateModel(); ko.attach("viewModel", vm); ko.attach("lstViewModel", vm2); </script>
会报错:
但是,如果是并列表使用,就不会:
<div class="con_c" data-model="viewModel"> </div> <div data-moel="lstViewModel"> </div>
<script type="text/javascript"> var vm = new ViewModel(); var vm2 = new CreateModel(); ko.attach("viewModel", vm); ko.attach("lstViewModel", vm2); </script>