Very simple JS bidirectional binding framework (II): Controller inheritance

Source: Internet
Author: User

Original intention

The previous article has implemented two-way binding of the data, but the model control is the entire document, in the actual project must have a scope, in order to do the UI module split.
In this article, we want to implement controller inheritance like Angularjs:
1. The model of the parent controller can be accessed in the child controller
2. The model of the child controller does not affect the parent controller
3. Controller inheritance is specified in HTML, not in JS

Goal

In HTML, use the Isi-controller property to declare the controller:

<body>    <div isi-controller="Parentcontroller">        <input data-bind="name">        <div isi-controller="Subcontroller">            <input data-bind="name">        </div>    </div></Body 

Hope that the above input name changed, the following will change, and the following changes, the above unchanged.
JS, define the controller with a function with the same name as above Isi-controller property value:

function ParentController() {    varnew Model();    model.set(‘name‘‘parent‘);}function ParentController() {    varnew Model();    model.set(‘name‘‘sub‘);}

For the user, just write this and it's over.

Realize

Very simple JS bidirectional binding framework (II): Controller inheritance

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.