簡體   English   中英

使用requirejs加載LayoutManager時的問題

[英]Issues in loading LayoutManager using requirejs

我是新來需要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;
});
function($, _, Backbone, LayoutManager

在這里,將其命名為LayoutManager。

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

在這里,您嘗試將其用作Backbone.LayoutView ...(它不存在(因此未定義))。 嘗試

App.Views.HelloView = LayoutView.extend({

您在此處使用的Backbone var與全局變量不同,請考慮requirejs :)

新版本的layoutmanager不使用“ LayoutView”來創建視圖。 使用Backbone.Layout.extend({...})來創建您的視圖...玩得開心..;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM