Javascript 下划线未捕获类型错误:无法调用方法';更换';未定义的
在我看来,我有:Javascript 下划线未捕获类型错误:无法调用方法';更换';未定义的,javascript,backbone.js,underscore.js,Javascript,Backbone.js,Underscore.js,在我看来,我有: noteTemplate:u3;.template($('#noteTemplate').html(), 这就抛出了这个错误。模板为: <script type="text/template" id="note-template"> <div class="reminder"> <div class="reminder-hover"> <div class="title"><%
noteTemplate:u3;.template($('#noteTemplate').html(),
这就抛出了这个错误。模板为:
<script type="text/template" id="note-template">
<div class="reminder">
<div class="reminder-hover">
<div class="title"><%= title %></div>
<div class="created">Created 3 days ago <span class="pull-right"> In 3 hours</span></div>
</div>
<span class="id" style="display: none;"><%= id %></span>
</div>
</script>
与其在定义方法时尝试缓存注释模板HTML,不如在初始化视图时进行缓存
initialize : function() {
// ...
this.nodeTemplate = _.template($('#note-template').html());
}
很可能是在加载DOM(以及模板)之前定义视图。另一种解决方案是将标记脚本移到调用视图的上方,如下所示(我使用的是jade)
initialize : function() {
// ...
this.nodeTemplate = _.template($('#note-template').html());
}
script#page-thumb(type='text/template')
.page-thumb-container.relative
.page-thumb
.image
figure
img(src='{{ image }}' , width='80px',height='60px' , data-id='{{ id }}')
span.title {{ title }}
.page-dragger.absolute
script(src='js/src/views/PageThumbView.js')