我有这个示例代码,用underscore模板渲染简单的未转义HTML。
var template = $(this.el).html(_.template(this.template, {'data': '<script>'}));
$(this.parent).append(template);
但是当我尝试渲染它时,却出现了错误:
Uncaught TypeError: 对象[object Object]没有方法'replace'
请问有人可以告诉我这是什么原因以及如何解决吗? 因为在underscore的文档中:
var template = _.template("<b><%- value %></b>");
template({value : '<script>'});
=> "<b><script></b>"
提前感谢。
this.template
是什么?是一个字符串,还是一个DOM或jQuery对象? - mu is too short