我有一个骨干应用程序,希望在触发时显示视图。当我单击锚点时,控制台会说:Uncaught TypeError: Cannot read property 'fn' of undefined
-我检查了此类其他问题,他们说未加载jQuery?wtf?我不明白...
我的菜单视图:
var LeftMenuView = Backbone.View.extend({
template: Handlebars.compile(Template),
events: {
'click li a.artAll': 'artAll',
},
artAll: function(event) {
event.preventDefault();
var artAllRouter = new Backbone.Router();
var route = '/artists/top100/all';
artAllRouter.navigate(route, {trigger: true});
}
....
控制台告诉我错误根源于handlebars.js
?
我的HTML模板:
<div>
{{#each}}
<p>
<a href="#">{{artist_name}}</a>
</p>
{{/each}}
</div>
和我的看法:
define(['backbone','handlebars', 'text!templates/TopAllArtists.html'],
function(Backbone,Handlebars, Template) {
var TopAllArtView = Backbone.View.extend({
template: Handlebars.compile(Template),
initialize: function () {
_.bindAll(this, 'render');
},
render: function() {
var self = this;
self.collection.each(function(model){
self.$el.append(self.template({
artist_name:model.get('artist_name')
})
);
});
return this;
}
});
return TopAllArtView;
}
);
有人知道这可能是什么问题吗?
根据“把手”文档,each
需要一个列表进行迭代,
<ul class="people_list">
{{#each people}}
<li>{{this}}</li>
{{/each}}
</ul>
是否需要重复艺术家姓名?
如果model.get('artist_name')
可迭代['name1', 'name2', ...]
,则
<div>
{{#each artist_name}}
<p>
<a href="#">{{this}}</a>
</p>
{{/each}}
</div>
如果model.get('artist_name')
是一个字符串,那么'Johann Sebastian Bach'
,
<div>
<p>
<a href="#">{{artist_name}}</a>
</p>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句