以下HTML在ajax调用中注入我的网站,但模板未被提取。注册它需要做些什么吗?
无法解析绑定属性。消息:
ReferenceError: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'));
答案 0 :(得分:1)
您需要将模板名称放在引号中,因此请输入名称:'answerTmpl'