开发者

Template not being found when injected dynamically

The HTML below is injected into my site on an ajax call, but the template is not being picked up. Is there something I need to do to register it?

Unable to parse binding attribute. Message:

ReferenceError: answerTmpl is not defined;

Attribute value: template: { name: answerTmpl, foreach: answers }

Dynamic HTML:

<script id="answerTmpl" type="text/html">
    <div>
      <span></s开发者_C百科pan>  <input type="checkbox" name="Answer" />
    </div>
</script>

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

Corresponding JS:

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


You need to put your template name in quotes, so name: 'answerTmpl'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜