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 – <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>
模板編譯時'profileT'中有什麼? – WiredPrairie 2013-03-13 19:14:26
現在我明白了,謝謝@WiredPrairie,在另一個視圖中我有另一個名爲profileT的變量,其中存儲了用於呈現藝術家個人資料的模板。看起來這些變量即使在不同的文件中也處於相同的範圍內= S我更改了其中一個變量的名稱,它起作用。 – Nocturn 2013-03-14 17:50:02