我刚开始需要js,我正在使用带有布局管理器的主干。我已经在下面粘贴了我的代码,我无法让布局管理器工作,我得到了这个错误:
"Uncaught TypeError: Cannot call method 'extend' of undefined"
在使用布局管理器的行中(Backbone.LayoutView.extend(
Main.js
require.config({
paths: {
jquery: 'lib/jquery-1.9.1.min',
underscore: 'lib/underscore-min',
backbone: 'lib/backbone-min',
handlebars: 'lib/handlebars',
layoutManager : 'lib/backbone.layoutmanager'
mousewheel : 'lib/jquery.mousewheel.min'
},
shim : {
'backbone' : {
deps: ['jquery', 'underscore' ],
exports: 'Backbone'
},
'layoutManager' : {
deps: ['jquery', 'underscore', 'backbone'],
exports: 'LayoutManager'
},
'mousewheel' : ['jquery']
}
});
require(["jquery", "underscore", "backbone", "layoutManager", "handlebars","mousewheel", "common"],function($, _, Backbone, LayoutManager, Handlebars,mousewheel, App) {
App.Views.HelloView = Backbone.LayoutView.extend({
template : '#hello_tmpl1',
});
App.Layouts.AppLayout = new BackBone.Layout({
template : '#layout',
views : {
".helloView" : new App.Views.HelloView()
}
});
$('body').empty().append(App.Layouts.AppLayout.el.render());
});
Common.js
define(function(){
var App = null;
App = { Models:{}, Views:{}, Collections:{}, Templates:{}, Router:{}, Layouts:{}};
return App;
});
function($, _, Backbone, LayoutManager
在这里你可以把它命名为LayoutManager。
App.Views.HelloView = Backbone.LayoutView.extend({
在这里,您可以尝试将其用作骨干。布局视图。。。它不存在(因此是未定义的(。尝试
App.Views.HelloView = LayoutView.extend({
这里的Backbone var与全局的不同,请考虑requirejs:(
新版本的layoutmanager不使用"LayoutView"来创建视图。使用主干。Layout.extend({…}(可创建视图。。。玩得开心…;(