强制本机淘汰赛模板 [英] Force native Knockout Templating

查看:60
本文介绍了强制本机淘汰赛模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要jQuery.tmpl的页面,但我想使用本机敲除模板作为

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

data-bind="foreach: Comments"

属性.因为我包含了jQuery.tmpl,所以禁用了基因敲除的本机模板.有什么办法可以强制执行本机功能?

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

谢谢

推荐答案

您不能在jQuery.tmpl模板中使用foreach或其他控制流绑定.

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>

或在变量中缓存本机模板引擎(new ko.nativeTemplateEngine())的副本.

or cache a copy of a native template engine (new ko.nativeTemplateEngine()) in a variable.

这篇关于强制本机淘汰赛模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆