How to create a node based on template parameter, then apply bindings to it.
Author: Gle2nnCreated Aug 9, 2021Updated Aug 9, 2021
A question rather than an issue per se. I am trying to write a template that will create either a 'div' or 'span' element and then populate it with markup. I have worked around the issue by testing the element name and creating the node and contents but am looking for a better way.
Pseudo-code (current):
if containerNode == "div" <div data-bind="attr: ...">...</div> if containerNode == "span" <span data-bind="attr: ...">...</span>
What I'd like to do is:
<ko createElementNode: "div"> ...Not sure how to specify the bindings that would apply to the node created in createElementNode.... </ko>
Thanks!
Source: knockout/knockout