Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout renderTemplate() rendering modes

I'm trying to call ko.renderTemplate() in a custom binding.

However I can't find any documentation for it's usage, particularly the rendering mode parameter.

Knockout.js pro tips – working with templates

The site above has a section "You can render templates directly from your custom bindings" that briefly describes the parameters to renderTemplate().

What are the other available options for the rendering mode parameter?

Additionally, is there any documentation for renderTemplate() and the rendering engine options that I may have missed?

like image 907
Brett Postin Avatar asked Nov 06 '12 13:11

Brett Postin


People also ask

How does Ko identify the template block that needs to be rendered?

Shorthand syntax: If you just supply a string value, KO will interpret this as the ID of a template to render. The data it supplies to the template will be your current model object.

What is Ko applyBindings?

For example, ko. applyBindings(myViewModel, document. getElementById('someElementId')) . This restricts the activation to the element with ID someElementId and its descendants, which is useful if you want to have multiple view models and associate each with a different region of the page.

How knockout js works in Magento 2?

Knockout JS is basically a type of JavaScript Library that is used for dynamically building certain parts of the Magento 2 frontend. It uses MVVM (Model-View-View-Model) pattern, which is a bit of a tricky structure to learn and implement in Magento 2.

How do I use knockout js in HTML?

It is very easy to use KnockoutJS. Simply refer the JavaScript file using <script> tag in HTML pages. A page as in the following image will be displayed. Click on download link and you will get the latest knockout.


2 Answers

Just from looking at the source code of 2.2.0.

The renderMode parameter seems to have two options:

  • replaceNode - This will replace the entire target node with the output of the template.
  • replaceChildren - Default. This will replace only the children of the target node, leaving the target node intact.
like image 71
gregpakes Avatar answered Oct 08 '22 20:10

gregpakes


You can find ko.renderTemplate() explained pretty well with some examples in this article.

like image 45
ADi3ek Avatar answered Oct 08 '22 20:10

ADi3ek