Dependencies between multiple models

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.