Template is a set of DOM elements that can be employed repetitively. Templating enables it simple to build complex applications because to its property of reducing duplication of DOM elements.
Mainly, there are 2 ways of creating templates:
Note that type is facilitated as text/html in script block for notifying KO that, it is not an executable block and is simple template block which requires to be rendered.
Combination of below properties can be sent as parameter-value to template.
Rendering a named template
Templates are defined implicitly by HTML markup inside DOM when employed with control flow bindings. But if you wish to, you can factor out templates into a distinct element and then refer them by name.
Following is an example of using foreach parameter including template name.
Following is how an alias can be generated for a foreach item:
By creating alias it becomes simple to point to parent objects from inside of foreach loops . This feature is advantageous when the code is complicated and nested at multiple levels.
There are some scenarios where in separate custom logic is required to be run on DOM elements created by template. In that case below callbacks can be employed. Look that you are employing foreach element then
afterAdd - This function is triggered when a new item is appended to array stated in foreach.
BeforeRemove - This function is triggered just before detaching the item from array stated in foreach.
AfterRender - Function stated here is triggered each time foreach is rendered and new entries are appended to array.
If there are various templates present then one can be selected dynamically by mentioning name as observable parameter. So template value will be again calculated as the name parameter alters and again data will be get re-rendered.
Please refer to official site for more information on this
KnockoutJS Related Interview Questions
|HTML 5 Interview Questions||Adv Java Interview Questions|
|MySQL Interview Questions||Angular JS Interview Questions|
|GNU Image Manipulation Program(GIMP) Interview Questions||Java Abstraction Interview Questions|
|jQuery Mobile Interview Questions||Advanced jQuery Interview Questions|
|Spring Boot Interview Questions||Bootstrap3 Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.