Javascript 未捕获类型错误:MyView不是函数
我创建了my-view.js文件,如下所示:Javascript 未捕获类型错误:MyView不是函数,javascript,backbone.js,Javascript,Backbone.js,我创建了my-view.js文件,如下所示: (function (Backbone) { var MyView = Backbone.View.extend({ className: 'card my-card', template: $('#my-template').html(), initialize: function(options) { this.render() }, render: function() { v
(function (Backbone) {
var MyView = Backbone.View.extend({
className: 'card my-card',
template: $('#my-template').html(),
initialize: function(options) {
this.render()
},
render: function() {
var html = _.template(this.template);
this.$el.html(html);
return this;
}
});
app.modules.MyView = MyView;
}(window.Backbone);
(function (Backbone) {
var MyDayCardView = app.modules.MyView,
var AppController = Backbone.View.extend({
initialize: function(){
var self = this;
},
appStart: function() {
this.MyDayCardView = new MyDayCardView();
self.$el.append(this.MyDayCardView.el);
}
});
app.controllers.AppController = new AppController();
}(window.Backbone);
在app-controller.js中,我写了如下内容:
(function (Backbone) {
var MyView = Backbone.View.extend({
className: 'card my-card',
template: $('#my-template').html(),
initialize: function(options) {
this.render()
},
render: function() {
var html = _.template(this.template);
this.$el.html(html);
return this;
}
});
app.modules.MyView = MyView;
}(window.Backbone);
(function (Backbone) {
var MyDayCardView = app.modules.MyView,
var AppController = Backbone.View.extend({
initialize: function(){
var self = this;
},
appStart: function() {
this.MyDayCardView = new MyDayCardView();
self.$el.append(this.MyDayCardView.el);
}
});
app.controllers.AppController = new AppController();
}(window.Backbone);
然后我得到了一个错误:
未捕获类型错误:MyView不是函数
Backbone.View.extend.appStart@app-controller.js:
我哪里做错了?您有一些语法问题,请参阅下面的代码
var app={};
app.modules={};
app.controllers={};
// Add your javascript here
(function (Backbone) {
var MyView = Backbone.View.extend({
className: 'card my-card',
template: $('#my-template').html(),
initialize: function(options) {
this.render()
},
render: function() {
var html = _.template(this.template);
this.$el.html(html);
return this;
}
});
app.modules.MyView = MyView;
}(window.Backbone));
(function (Backbone) {
var MyDayCardView = app.modules.MyView,
AppController = Backbone.View.extend({
initialize: function(){
var self = this;
},
appStart: function() {
this.MyDayCardView = new MyDayCardView();
self.$el.append(this.MyDayCardView.el);
}
});
app.controllers.AppController = new AppController();
}(window.Backbone));
您有一些语法问题,请参阅下面的代码
var app={};
app.modules={};
app.controllers={};
// Add your javascript here
(function (Backbone) {
var MyView = Backbone.View.extend({
className: 'card my-card',
template: $('#my-template').html(),
initialize: function(options) {
this.render()
},
render: function() {
var html = _.template(this.template);
this.$el.html(html);
return this;
}
});
app.modules.MyView = MyView;
}(window.Backbone));
(function (Backbone) {
var MyDayCardView = app.modules.MyView,
AppController = Backbone.View.extend({
initialize: function(){
var self = this;
},
appStart: function() {
this.MyDayCardView = new MyDayCardView();
self.$el.append(this.MyDayCardView.el);
}
});
app.controllers.AppController = new AppController();
}(window.Backbone));
此代码不可能在您的浏览器中运行,错误百出。您确定my-view.js在controller.js之前执行吗?此代码不可能在您的浏览器中运行,错误百出。您确定my-view.js在controller.js之前执行吗?