knockout / knockout

Knockout makes it easier to create rich, responsive UIs with JavaScript
http://knockoutjs.com/
Other
10.43k stars 1.52k forks source link

How to create a node based on template parameter, then apply bindings to it. #2574

Open Gle2nn opened 2 years ago

Gle2nn commented 2 years ago

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"

...
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!