Force native Knockout Templating

不羁岁月 提交于 2019-12-06 06:48:37

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/9750724/force-native-knockout-templating

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