Learn Uncle Tom's Knockout tutorial notes (ii)

Source: Internet
Author: User

Template binding

Objective

Template binding uses templates to render data to a page. Template bindings are very handy for building nested structures of pages. By default, Knockout is using the popular Jquery.tmpl template engine. With it, you need to download and reference the Jquery.tmpl and jquery frameworks on the installation page. Or you can integrate other template engines (although you need to know knockout internal knowledge).

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <Scripttype= "Text/javascript"src= "Libs/jquery-1.12.2.min.js"></Script>    <Scripttype= "Text/javascript"src= "Libs/jquery.tmpl.min.js"></Script>    <Scripttype= "Text/javascript"src= "Libs/knockout-3.4.0.js"></Script>    <MetaCharSet= "UTF-8"></Head><Body><DivData-bind= ' Template:"Persontemplate" '> </Div><ScriptID= ' Persontemplate 'type= ' text/html '>${Name} is ${age} years old<button Data-Bind='Click:makeolder'>Make older</button></Script><Scripttype= ' Text/javascript '>    varViewModel={name:ko.observable ('Bert'), age:ko.observable ( +), Makeolder:function () {             This. Age ( This. Age ()+1);    }    }; Ko.applybindings (ViewModel);</Script></Body></HTML>

When the referenced observable (dependent observable) data changes, knockout automatically re-render the template. In this example, the template will be re-render each time the button is clicked.

Learn Uncle Tom's Knockout tutorial notes (ii)

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.