KO找不到带ID的模板 [英] KO cannot find template with ID

查看:122
本文介绍了KO找不到带ID的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前我使用过Knockout模板,所以我不确定为什么这对我不起作用。
我尝试了两种不同风格的ko标记,但都不起作用。

I've used Knockout templates before, so I'm not sure why this isn't working for me. I tried two different styles of ko markup, neither work.

<!-- more nesting levels -->
<div class="cal-day-tps" data-bind="foreach: timePeriods">
    <div class="cal-day-tp-cont">

        <div data-bind="template: { name: 'tp-ed-templ', data: $data }"></div>

        //both of these methods fail
        <!-- ko template: { name: 'tp-ed-templ', data: $data } -->
        <!-- /ko -->

    </div>
</div>    
<!-- /more nesting levels -->


<script type="text/html" id="tp-ed-templ">
 <!-- bunch of markup -->
</script>

我刚收到错误无法找到ID为tp-ed-templ的模板。

I just get the error "Cannot find template with ID tp-ed-templ".

可能只是一个错字,但我找不到它。

Probably just a typo, but I haven't been able to find it.

  • I'm using KO in the context of Durandal, though this shouldn't make a difference.
  • Tried declaring the template before usage, didn't help.
  • Someone else ran into the same thing with no solution either

这似乎是Durandal的一个问题,而不是Knockout

我在vanilla durandal设置中尝试了一些非常简单的案例,它仍然做同样的事情。甚至尝试将脚本放在与绑定相同的嵌套位置,没有骰子。

I tried some extremely simple cases in vanilla durandal setups, and it still does the same thing. Even tried putting the script in the same nested location as the binding, no dice.

推荐答案

简答:你不能目前在
但是, nemesv 指出,如果你将你的命名模板放在Durandal之外,ko就能找到它们。例如,< div id =applicationHost>< / div> 元素之外的任何地方。

The short answer: You can't currently use Knockout templates inside of Durandal. However, as nemesv pointed out, if you put your named template outside of Durandal, ko is able to find them. For example, anywhere outside of the <div id="applicationHost"></div> element.

其他解决方法是使用Durandal的撰写功能,或者只是将模板内联为匿名。

The other workarounds are to either use Durandal's compose functionality, or just inline the templates as anonymous.

在不久的将来可能会支持Knockout模板。

Knockout templates will probably be supported in the near future.

我终于在Durandal google小组上挖出了这些答案,

I finally dug these answers up on the Durandal google group,

  • Mixing knockout templates with durandal compose
  • knockout can't find templates inside of views

这篇关于KO找不到带ID的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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