【发布时间】:2015-03-06 18:09:20
【问题描述】:
我的 index.jade 中有以下模板:
....
<script type="text/template" id="sample-template">
a(href="<%= link.href %>") <%= link.title %>
</script>
....
我的主干视图中有以下代码,它将一个名为 link 的变量发送到 index.jade。
....
var SampleView = Backbone.View.extend({
template: _.template($('#sample-template').html()),
render: function() {
this.$el.append(this.template({
link: this.model.toJSON()
}));
return this;
}
});
....
现在,当我渲染该模板时,我得到以下输出:
<a href="<%= link.href %>"> sample link
你看,我得到了 title 变量的正确输出。但问题在于href。它不会打印link.href 的值。
【问题讨论】:
-
您是否尝试过从 href 赋值中删除双引号?请参阅this 答案。
-
@pdoherty926 是的,我删除了双引号,但出现以下错误:
unexpected token <
标签: javascript node.js backbone.js pug