require.js未捕获类型错误:对象#&LT的属性“$”;对象>不是一个函数 [英] require.js Uncaught TypeError: Property '$' of object #<Object> is not a function

查看:292
本文介绍了require.js未捕获类型错误:对象#&LT的属性“$”;对象>不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用require.js首次,但我得到了错误:


  

遗漏的类型错误:#对象的属性$不是一个函数


  require.config({
      垫片:{       jQuery的:{
            出口:$
        },        强调:{
          出口:'_'
        },
        主干:{
          DEPS:['下划线','jQuery的'],
          出口:骨干
        }
      },
      路径:{
        jQuery的://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min',
        强调://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min',
        主干网://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min',
        模板:'/ referralgenie /模板/
      }    });    要求([
      应用程序
    ],功能(APP){
      App.initialize();
    });

它指出的错误是在Backbone.js的,所以我很难找到它的调试。

这个错误来自该行的位置:

  Backbone.history.start();

在我的路由器文件:

  //文件名:router.js
定义([
  jQuery的,
  下划线,
  '骨干',
  意见/ CampaginView',
  意见/ RewardView',
  意见/ FriendRewardView',
  意见/ ParticipantView
]函数($,_,骨干,CampaginView,RewardView,FriendRewardView,ParticipantView){
   VAR AppRouter = Backbone.Router.extend({
           路线:{
               ':ID:门户的家//匹配http://example.com/#anything-here
           }
    });
  VAR初始化函数=(){    VAR app_router =新AppRouter;    app_router.on('路线:门入户',函数(ID){
      VAR campaignView =新CampaginView();
      campaignView.render({ID:ID});
    });
    Backbone.history.start();
  };
  返回{
    初始化:初始化
  };
});


解决方案

这是基于这样的预感<一个href=\"http://stackoverflow.com/questions/17771858/property-of-object-object-is-not-a-function-at-extend-ensureelement\">SO问题/答案并基于阅读的 Backbone.js的中的code。

我觉得骨干,是很难找到的jQuery,所以你必须自己设置。尝试使用带有的init 功能骨干垫片做到这一点:

 骨干:{
      DEPS:['下划线','jQuery的'],
      出口:'骨干',
      初始化:功能(_,$){$骨干= $;返回骨干; }
    }

I'm trying to use require.js for the first time, however I'm getting the error:

Uncaught TypeError: Property '$' of object # is not a function.

 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.

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.

I think Backbone is having trouble finding jQuery so you'll have to set it yourself. Try to do it by using a shim with an init function for Backbone:

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

这篇关于require.js未捕获类型错误:对象#&LT的属性“$”;对象&gt;不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆