Backbone,Marionette无法识别ItemView:undefined不是一个函数

时间:2013-09-16 16:09:02

标签: backbone.js marionette

我不明白为什么我的ItemView上出现了这个错误。

这是我的main.js

require.config({
    baseUrl: '/',
    paths: {

        jquery: 'scripts/lib/jquery/jquery.min',
        backbone: 'scripts/lib/backbone/backbone.min',
        underscore: 'scripts/lib/underscore/underscore-min',

        //Core Libraries
        marionette: 'scripts/lib/marionette/marionette.min',
        text: 'scripts/lib/text/text',
        async :'scripts/lib/async'
    },
    shim: {
        jquery: {
            exports: '$'
        },
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: [ 'underscore', 'jquery' ],
            exports: 'Backbone'
        },
        marionette : {
            deps : ['jquery', 'underscore', 'backbone'],
            exports : 'Marionette'
        }
    }
});

require([
    'jquery',
    'underscore',
    'backbone',
    'marionette'
], function () {

    // create the app
    var App = new Marionette.Application();

    App.addRegions({
        map : '#Map'
    });


    App.addInitializer( function() {
        var self = this;
        require(['scripts/views/map']
        , function(MapView){
            self.map.show( new MapView() );
        });
    });

    App.start();

    window.App = App;
});

然后这是我的maps.js

define([
    'jquery',
    'underscore',
    'text!scripts/templates/map.html',
    'async!https://maps.googleapis.com/maps/api/js?v=3&sensor=true'
], function($, _, mapTemplate) {

    var MapView = Marionette.ItemView.extend({

        template: _.template( mapTemplate ),

        ui:  {
            mapContainer: '#map-container' 
        },

        onRender: function() {
            var self = this;

            var mapOptions = {
                zoom: 8,
                center: new google.maps.LatLng(-34.397, 150.644),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map = new google.maps.Map(this.ui.mapContainer, mapOptions);

        }
    });

    return MapView;
});

我是骨干和牵线木偶的新手,所以我不确定为什么我会收到错误:

未捕获的TypeError:undefined不是函数 在这一行:

self.map.show( new MapView() );

1 个答案:

答案 0 :(得分:0)

你不是'要求'木偶(或者访问它的完全限定名称Backbone.Marionette)