Ko. applybindings
Second parameter (optional)
It can be declared as an HTML element or container that uses data-bind. For example, Ko. applybindings (myviewmodel, document. getelementbyid ('someelementid ')). Currently, only elements and sub-elements used as someelementid can activate the Ko function. The advantage is that you can declare multiple view models on the same page to differentiate regions.
Note that if multiple models exist, any of them is specified with elements, and other models also need to specify elements.
See the following example.
<script src="Scripts/jquery-1.7.1.js" type="text/javascript"></script><script src="Scripts/knockout-3.1.0.js" type="text/javascript"></script> <title></title>
Result:
The personname is not bound. If you need to bind it, each model needs to specify elements, which is amazing.
If a grid contains select, there is no way to depend on it.
The solution is as follows:
Https://github.com/sergun/Knockout-MultiModels
1. Add the following Js. js has a sequential relationship.
<script src="Scripts/jquery-1.7.1.js" type="text/javascript"></script> <script src="Scripts/knockout-3.1.0.js" type="text/javascript"></script> <script type="text/javascript" src="Scripts/jquery.livequery.js"></script> <!--Plugin--> <script type="text/javascript" src="Scripts/knockout.multimodels-0.1.js"></script>
2. Change KO. applybindings to Ko. Attach, append the model name, and specify the object name for the element.
Running Effect
Dependencies between multiple models