简体   繁体   English

使用requirejs加载LayoutManager时的问题

[英]Issues in loading LayoutManager using requirejs

I'm new to require js and i'm using backbone with layout manager. 我是新来需要js的人,而且我正在使用带有布局管理器的主干。 I've pasted my code below and i'm not able to get the layout manager to work and i get this error : 我在下面粘贴了我的代码,但我无法使布局管理器正常工作,并且出现此错误:

 "Uncaught TypeError: Cannot call method 'extend' of undefined" 

in line where layoutmanager is used (Backbone.LayoutView.extend) 在使用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;
});
function($, _, Backbone, LayoutManager

Here you name it LayoutManager. 在这里,将其命名为LayoutManager。

App.Views.HelloView = Backbone.LayoutView.extend({

Here you try to use it as Backbone.LayoutView... which doesn't exist (thus the undefined). 在这里,您尝试将其用作Backbone.LayoutView ...(它不存在(因此未定义))。 Try 尝试

App.Views.HelloView = LayoutView.extend({

The Backbone var you have here is different from the global one, think requirejs :) 您在此处使用的Backbone var与全局变量不同,请考虑requirejs :)

New version of layoutmanager doesn't use 'LayoutView' to create views. 新版本的layoutmanager不使用“ LayoutView”来创建视图。 Use Backbone.Layout.extend({ ...}) to create your views ... have fun .. ;) 使用Backbone.Layout.extend({...})来创建您的视图...玩得开心..;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM