【问题标题】:Template not being found when injected dynamically动态注入时找不到模板
【发布时间】:2011-07-23 17:41:18
【问题描述】:

通过 ajax 调用将下面的 HTML 注入我的网站,但没有提取模板。我需要做些什么来注册它吗?

无法解析绑定属性。留言:
参考错误:answerTmpl 未定义;
属性值:template: { name: answerTmpl, foreach: answers }

动态 HTML:

<script id="answerTmpl" type="text/html">
    <div>
      <span></span>  <input type="checkbox" name="Answer" />
    </div>
</script>

<div id="answers" data-bind="template: { name: answerTmpl, foreach: answers }"></div>

对应的JS:

ko.applyBindingsToNode(document.getElementById('answers'));

【问题讨论】:

    标签: knockout.js jquery-templates


    【解决方案1】:

    您需要将模板名称放在引号中,因此 name: 'answerTmpl'

    【讨论】:

    • 谢谢你的第二双眼睛。
    • 是的,如果您一遍又一遍地看,很容易错过这一点
    猜你喜欢
    • 2019-10-30
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多