简体   繁体   English

require.js未捕获的TypeError:对象的属性&#39;$&#39; <Object> 不是一个功能

[英]require.js Uncaught TypeError: Property '$' of object #<Object> is not a function

I'm trying to use require.js for the first time, however I'm getting the error: 我第一次尝试使用require.js,但是我收到了错误:

Uncaught TypeError: Property '$' of object # is not a function. 未捕获的TypeError:对象#的属性'$'不是函数。

 require.config({
      shim: {

       "jquery": {
            exports: '$'
        },

        underscore: {
          exports: '_'
        },
        backbone: {
          deps: ['underscore', 'jquery'],
          exports: 'Backbone'
        }
      },
      paths: {
        jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min',
        underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min',
        backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min',
        templates: '/referralgenie/templates/'
      }

    });

    require([
      'app'
    ], function(App){
      App.initialize();
    });

It states the error is in backbone.js so I'm finding it hard to debug. 它声明错误在backbone.js中,所以我发现很难调试。

The error comes from the line here: 错误来自这里的行:

Backbone.history.start();

In my Router file: 在我的路由器文件中:

// Filename: router.js
define([
  'jquery',
  'underscore',
  'backbone',
  'views/CampaginView',
  'views/RewardView',
  'views/FriendRewardView',
  'views/ParticipantView'
], function($, _, Backbone, CampaginView, RewardView, FriendRewardView, ParticipantView) {


   var AppRouter = Backbone.Router.extend({
           routes: {
               ':id': 'portal-home' // matches http://example.com/#anything-here
           }
    });


  var initialize = function(){

    var app_router = new AppRouter;

    app_router.on('route:portal-home',function(id) {
      var campaignView = new CampaginView();
      campaignView.render({id: id});
    });




    Backbone.history.start();
  };
  return {
    initialize: initialize
  };
});

This is a hunch based on this SO question/answer and based on reading the code of Backbone.js . 这是基于这个SO问题/答案并基于阅读Backbone.js代码的预感。

I think Backbone is having trouble finding jQuery so you'll have to set it yourself. 我认为Backbone很难找到jQuery,所以你必须自己设置它。 Try to do it by using a shim with an init function for Backbone: 尝试使用带有Backbone的init函数的垫片:

    backbone: {
      deps: ['underscore', 'jquery'],
      exports: 'Backbone',
      init: function (_, $) { Backbone.$ = $; return Backbone; }
    }

暂无
暂无

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

相关问题 Require.js:未捕获的TypeError:对象函数…没有方法 - Require.js : Uncaught TypeError: Object function … has no method Require.js未被捕获的TypeError:jqOAuth不是一个函数 - Require.js Uncaught TypeError: jqOAuth is not a function Require.js Uncaught TypeError:undefined不是函数 - Require.js Uncaught TypeError: undefined is not a function Backbone.js和Require.js-未捕获的TypeError:对象函数(){return parent.apply(this,arguments); }没有方法“开” - Backbone.js and Require.js - Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'on' 未捕获的TypeError:使用require.js时undefined不是函数 - Uncaught TypeError: undefined is not a function when using require.js JS:Uncaught TypeError:对象[object Object]的属性&#39;$&#39;不是函数 - JS: Uncaught TypeError: Property '$' of object [object Object] is not a function require.js uncaught typeerror:无法读取属性&#39;__module_path__; 未定义的 - require.js uncaught typeerror: cannot read property '__module_path__; of undefined 未捕获的TypeError:对象[对象全局]的属性'$'不是函数? - Uncaught TypeError: Property '$' of object [object global] is not a function? 未捕获的TypeError:对象[object DOMWindow]的属性不是函数 - Uncaught TypeError: Property of object [object DOMWindow] is not a function 未捕获的TypeError:对象[对象DOMWindow]的属性&#39;$&#39;不是函数 - Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM