Force native Knockout Templating

半世苍凉 提交于 2019-12-04 12:40:04

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!