【问题标题】:Backbone, Marionette not recognizing ItemView: undefined is not a functionBackbone,Marionette 无法识别 ItemView:未定义不是函数
【发布时间】:2013-09-20 20:58:54
【问题描述】:

我不明白为什么我的 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;
});

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

Uncaught TypeError: undefined is not a function 在这一行:

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

【问题讨论】:

    标签: backbone.js marionette


    【解决方案1】:

    您不是“需要”木偶(或者访问它的完全限定名称 Backbone.Marionette)

    【讨论】:

    • 我没关注,我在 main.js 中定义了它
    猜你喜欢
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多