1
我正在尝试与backbone.js看一看peepcode视频。但是我得到了我在主题中写的错误。Backbone.js:TypeError:对象[对象对象]的属性'模板'不是函数
在我来说,我有一个小脚本和一个索引文件:
<!DOCTYPE html>
<html>
<head>
<title>Backbone App</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
<script src="js/jquery.min.js"></script>
<script src="js/underscore.js"></script>
<script src="js/backbone.js"></script>
<script src="js/Tunes.js"></script>
<script type="text/template" id="album-template">
<span class="album-title"><%= title %></span>
<span class="album-artist"><%= artist %></span>
<ol class="tracks">
<% _.each(tracks, function(){ %>
<li><%= track.title %></li>
<% }); %>
</ol>
</script>
</head>
<body>
<div class="container">
<div class="navbar">
<a href="./">Startseite</a>
</div>
</div>
</body>
</html>
我的脚本:
(function($){
window.Album = Backbone.Model.extend({});
window.AlbumView = Backbone.View.extend({
template: "#album-template",
tag: 'li',
className: 'album',
intialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
this.template = _.template($('#album-template').html());
},
render: function() {
var $el = $(this.el),
renderedContent = this.template(this.model.toJSON());
$el.html(renderedContent);
return this;
}
});
}(jQuery));
有谁知道这个错误,可以帮我解决这个问题?
感谢,
皮特
哪一行给出错误?注意你有两个'template'变量'template:“#album-template”'和'this.template' –
表面上你的代码对我来说看起来很好,但是如果你能提供更多的调试信息很有帮助。具体来说,如果你可以在你的'render'函数中添加以下内容并告诉我们记录的是什么:'console.log(这个,这个实例的AlbumView,this.template,typeof this.template);', – machineghost