سؤال

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></span>  <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'

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top