0

我正在使用 jquery mobile、backbone.js、marionette.js 和 require.js 构建应用程序。我目前正在尝试在视图中使用 jQuery 移动页面加载小部件,但我收到此错误

Uncaught TypeError: Cannot read property 'loader' of undefined 

我的应用程序的起点如下所示

 require.config({
    paths: {
         jquery: 'vendor/jquery-1.9.1.min',
        'jquery.mobile': 'vendor/jquery.mobile-1.3',
        'jquery.mobile-config': 'vendor/jquery.mobile.config',
        underscore: 'vendor/backbone/underscore',
        backbone: 'vendor/backbone/backbone',
        marionette: 'vendor/marionette/backbone.marionette',
        text: 'vendor/text'
    },

    shim: {
        underscore: {
            exports: '_'
        },

        backbone: {
            exports: 'Backbone',
            deps: ['jquery','underscore']
        },

        'jquery.mobile-config': ['jquery'],
        'jquery.mobile': ['jquery','jquery.mobile-config'],

        marionette: {
            exports: 'Backbone.Marionette',
            deps: ['backbone']
        }
    }
});

require(['jquery','app', 'jquery.mobile'], function ($, App) {
    $(function() {
        App.start();
    });
});

jquery.mobile.config 文件看起来像这样

define(['jquery'], function ($) {
      $(document).bind("mobileinit", function () {
          $.extend(  $.mobile , {autoInitializePage: false});
          $.mobile.ajaxEnabled = false;
          $.mobile.linkBindingEnabled = false;
          $.mobile.hashListeningEnabled = false;
          $.mobile.pushStateEnabled = false;
      });
});

视图看起来像这样

define(['jquery', 'marionette','text!templates/login.html'], function ($, marionette, ViewTemplate) {

    'use strict';

    var LoginView = marionette.ItemView.extend({

        template: _.template(ViewTemplate),

        events: {
            'click #login-btn': 'login'
        },

        login: function (event) {

            $.mobile.loading('show', {
                text: 'Please wait',
                textVisible: true
            });
        }
    });

    return LoginView;
});

可能是什么问题呢?

4

1 回答 1

0

Could be DOM not ready yet, jqm not loaded yet try using something like that (or equivalent):

jQuery(document).ready(function () {
    viewModel.login();
});
于 2014-11-06T19:59:52.577 回答