TypeError: undefined is not an object (evaluating 'Marionette.LayoutView.extend')
TypeError: undefined is not an object (evaluating 'Marionette.LayoutView.extend')
学习 Marionette 并尝试使用 Marionette LayoutView 创建区域。我收到了问题标题中描述的错误消息。看了很多遍代码,就是看不出问题出在哪里。希望有人能告诉我。谢谢。显然问题行是 Marionette.LayoutView 未定义,我不知道为什么:
var AppLayoutView = Marionette.LayoutView.extend(
var Marionette = require('backbone.marionette'),
Controller = require('./controller'),
Router = require('./router'),
UserModel = require('./models/user'),
UsersCollection = require('./collections/users');
module.exports = App = function App() {};
App.prototype.start = function(){
App.core = new Marionette.Application();
App.core.on("initialize:before", function (options) {
//App.core.vent.trigger('app:log', 'App: Initializing');
App.views = {};
App.data = {};
//define the App regions
var AppLayoutView = Marionette.LayoutView.extend({
template: "#app-container",
regions: {
headerRegion: "#header-region",
mainRegion: "#main-region",
drawerRegion: "#drawer-region",
dialog: "#dialog-region"
}
});
App.mainlayout = new AppLayoutView();
App.mainlayout.render();
var DashLayoutView = Marionette.LayoutView.extend({
template: "#dashboard-template",
regions: {
dashHeaderRegion: "#dbheader-region",
dashMainRegion: "#dbmain-region",
}
});
App.dashlayout = new DashLayoutView();
App.dashlayout.render();
// load up some initial data:
var users = new UsersCollection();
users.fetch({
success: function() {
App.data.users = users;
App.core.vent.trigger('app:start');
}
});
});
App.core.vent.bind('app:start', function(options){
//App.core.vent.trigger('app:log', 'App: Starting');
if (Backbone.history) {
App.controller = new Controller();
App.router = new Router({ controller: App.controller });
//App.core.vent.trigger('app:log', 'App: Backbone.history starting');
Backbone.history.start();
}
//new up and views and render for base app here...
//App.core.vent.trigger('app:log', 'App: Done starting and running!');
});
App.core.vent.bind('app:log', function(msg) {
console.log(msg);
});
App.core.start();
};
我承认我发的问题有歧义。我很抱歉。我学习过程的一部分。无论如何,为了记录,我已经重构了我的代码,如下所示,现在对我有用。
var Marionette = require('backbone.marionette'),
Controller = require('./controller'),
Router = require('./router');
App = new Marionette.Application();
App.on("before:start", function(){
App.addRegions({
headerRegion: "#header-region",
mainHeaderRegion: "#content-header",
mainRegion: "#main-region",
drawerRegion: "#drawer-region",
dialog: "#dialog-region"
});
});
App.on("start", function(){
if (Backbone.history) {
App.controller = new Controller();
App.router= new Router({ controller: App.controller });
//App.core.vent.trigger('app:log', 'App: Backbone.history starting');
Backbone.history.start();
}
});
App.vent.bind('app:log', function(msg) {
console.log(msg);
});
App.start();
学习 Marionette 并尝试使用 Marionette LayoutView 创建区域。我收到了问题标题中描述的错误消息。看了很多遍代码,就是看不出问题出在哪里。希望有人能告诉我。谢谢。显然问题行是 Marionette.LayoutView 未定义,我不知道为什么:
var AppLayoutView = Marionette.LayoutView.extend(
var Marionette = require('backbone.marionette'),
Controller = require('./controller'),
Router = require('./router'),
UserModel = require('./models/user'),
UsersCollection = require('./collections/users');
module.exports = App = function App() {};
App.prototype.start = function(){
App.core = new Marionette.Application();
App.core.on("initialize:before", function (options) {
//App.core.vent.trigger('app:log', 'App: Initializing');
App.views = {};
App.data = {};
//define the App regions
var AppLayoutView = Marionette.LayoutView.extend({
template: "#app-container",
regions: {
headerRegion: "#header-region",
mainRegion: "#main-region",
drawerRegion: "#drawer-region",
dialog: "#dialog-region"
}
});
App.mainlayout = new AppLayoutView();
App.mainlayout.render();
var DashLayoutView = Marionette.LayoutView.extend({
template: "#dashboard-template",
regions: {
dashHeaderRegion: "#dbheader-region",
dashMainRegion: "#dbmain-region",
}
});
App.dashlayout = new DashLayoutView();
App.dashlayout.render();
// load up some initial data:
var users = new UsersCollection();
users.fetch({
success: function() {
App.data.users = users;
App.core.vent.trigger('app:start');
}
});
});
App.core.vent.bind('app:start', function(options){
//App.core.vent.trigger('app:log', 'App: Starting');
if (Backbone.history) {
App.controller = new Controller();
App.router = new Router({ controller: App.controller });
//App.core.vent.trigger('app:log', 'App: Backbone.history starting');
Backbone.history.start();
}
//new up and views and render for base app here...
//App.core.vent.trigger('app:log', 'App: Done starting and running!');
});
App.core.vent.bind('app:log', function(msg) {
console.log(msg);
});
App.core.start();
};
我承认我发的问题有歧义。我很抱歉。我学习过程的一部分。无论如何,为了记录,我已经重构了我的代码,如下所示,现在对我有用。
var Marionette = require('backbone.marionette'),
Controller = require('./controller'),
Router = require('./router');
App = new Marionette.Application();
App.on("before:start", function(){
App.addRegions({
headerRegion: "#header-region",
mainHeaderRegion: "#content-header",
mainRegion: "#main-region",
drawerRegion: "#drawer-region",
dialog: "#dialog-region"
});
});
App.on("start", function(){
if (Backbone.history) {
App.controller = new Controller();
App.router= new Router({ controller: App.controller });
//App.core.vent.trigger('app:log', 'App: Backbone.history starting');
Backbone.history.start();
}
});
App.vent.bind('app:log', function(msg) {
console.log(msg);
});
App.start();