Question

I have a page that requires jQuery.tmpl, but I want to use native knockout templating for a

data-bind="foreach: Comments"

attribute. Because I have included jQuery.tmpl, knockout's native templating is disabled; is there a way that I can force the native functionality?

Thanks

Was it helpful?

Solution

You cannot use foreach or other control-flow bindings within a jQuery.tmpl template.

However, if you want to call a named template and force it to use the native template 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 a native template engine (new ko.nativeTemplateEngine()) in a variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top