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)