Customize knockout patterns
1 answer
You cannot use foreach
or other control flow bindings in the jQuery.tmpl template.
However, if you want to call a named template and force it to use its own templating engine, then you would do something like:
<div data-bind="template: { name: 'itemsTmpl', templateEngine: new ko.nativeTemplateEngine() }">
</div>
<script id="itemsTmpl" type="text/html">
<ul data-bind="foreach: items">
<li data-bind="text: $data"></li>
</ul>
</script>
or cache a copy of the built-in templating engine ( new ko.nativeTemplateEngine()
) in a variable.
+5
source to share