我有一个用户模型,每个用户都有一个艺术家,每个艺术家都有几张专辑。我正在尝试渲染视图以显示用户配置文件。当我尝试渲染视图时,出现以下错误:
Uncaught ReferenceError: albums is not defined
(anonymous function) b.template.c underscore-min.js:30
Backbone.View.extend.render profile.js:13
Backbone.Router.extend.profile router.js:62
...
似乎我没有将专辑对象传递给模板,但我没有在该模板中使用任何专辑变量,也没有在视图中使用。这是两者的代码:
看法:
headerT = require('text!templates/user/profile_header.html');
profileT = require('text!templates/user/profile.html');
var profilesView = Backbone.View.extend({
el: $('#main-container'),
initialize: function(){
this.template = _.template(profileT);
this.artist = this.model.get('artist');
},
render: function(){
$(this.el).html(this.template({
current_user: app.current_user,
user: this.model.toJSON(),
artist: this.artist.toJSON(),
}));
return this;
},
});
模板:
<div class="row">
<div class="grid_3">
<img src="<%=user.pict%>" class="frame" alt="">
<span class="title">Username – <strong><%=user.username%></strong></span>
<%if(current_user!=undefined && (current_user.get('is_admin') == true || current_user.get('id') == user.id)){%>
<span class="title"><span class="icon user"></span> <a href="#/editProfile/">Edit Profile</a></span>
<%}%>
<%if(artist.active==true){%>
<div><a href="#/artistProfile/">Go to Artist Profile</a></div>
<%}%>
<div class="separator"></div>
</div>
<div class="clear"></div>
</div>