嘿我不确定为什么这个Backbone视图显示为引用错误,指出UserView未定义。用户模型显示为一个功能,以便工作。我也在jsfiddle上使用JSLint运行我的代码,js明智没问题,或者在那里?
以下代码
var User = Backbone.Model.extend({
defaults: {
firstName: 'J.R.',
lastName: 'Smith',
email: 'jsmith@knicks.com',
phone: '212-424-6234',
birthday: '03/05/1982',
city: 'New York'
},
location: function(){
return this.get('firstName') + ' ' + this.get('lastName') + 'is currently in ' + this.get('city') + '.';
}
});
var UserView = Backbone.View.extend({
tagName: 'li',
initialize: function() {
this.render();
},
render: function() {
$(this.el).html( this.model.get('firstName'));
}
});
var user = new User();
var userView = new UserView({model: user});
答案 0 :(得分:0)
你必须在window.load函数中删除跟随内容。
var user = new User();
var userview = new UserView({model: user});
因为if不在window.load函数中,当你调用UserView的