开发者

Template not being found when injected dynamically

开发者 https://www.devze.com 2023-03-22 16:41 出处:网络
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?

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

精彩评论

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