我是新手,需要js,我正在使用骨干与布局管理器。我已粘贴下面的代码,我无法让布局管理器工作,我收到此错误:
"Uncaught TypeError: Cannot call method 'extend' of undefined"
在使用layoutmanager的地方(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;
});
答案 0 :(得分:0)
function($, _, Backbone, LayoutManager
在此您将其命名为LayoutManager。
App.Views.HelloView = Backbone.LayoutView.extend({
在这里,您尝试将其用作Backbone.LayoutView ...它不存在(因此未定义)。尝试
App.Views.HelloView = LayoutView.extend({
你在这里的Backbone var与全局的不同,想想requirejs:)
答案 1 :(得分:0)
新版本的layoutmanager不使用'LayoutView'来创建视图。使用Backbone.Layout.extend({...})创建您的视图......玩得开心..;)