2013-03-13 53 views
0

我有一个用户模型,每个用户有一个艺术家,每个艺术家有几个相册。我试图呈现一个视图来显示用户配置文件。当我试图使我得到以下错误的观点:骨干视图要求的模型林不使用

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 &ndash; <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>  
+0

模板编译时'profileT'中有什么? – WiredPrairie 2013-03-13 19:14:26

+0

现在我明白了,谢谢@WiredPrairie,在另一个视图中我有另一个名为profileT的变量,其中存储了用于呈现艺术家个人资料的模板。看起来这些变量即使在不同的文件中也处于相同的范围内= S我更改了其中一个变量的名称,它起作用。 – Nocturn 2013-03-14 17:50:02

回答

0

我改变了正拿着模板变量的名称和它的工作。我有另一个相同名称的变量,在另一个文件中保存了一个不同的模板(其中有专辑),并且它正在加载该模板。我认为范围不同,因为它在另一个文件中,但它没有。