如何在RequireJS和BackboneJS中包含Jquery插件

时间:2014-02-21 14:39:56

标签: jquery backbone.js requirejs

我想在BackboneJS / RequireJS应用程序中使用图像Lazyload.js插件,但不知道如何执行此操作。任何人都可以提示吗?这是我想要使用的插件lazyload plugin

我已经下载并在我的config.js中定义了它:

require.config({

 paths: {   
      jquery: '../lib/jquery-2.0.3.min',
      underscore: '../lib/lodash-2.2.1.min',
      backbone: '../lib/backbone-1.0.0.min',     
     lazyload: '../lib/jquery.lazyload.min'
 },

 shim: {backbone, handlebars etc...}

});

我读过我必须申请一些:

define(["jquery"], 
   function($){
   ...
});

在插件代码的末尾?

1 个答案:

答案 0 :(得分:0)

我正在复制我的文件..从这里你可以得到体面的想法如何在骨干中包含jquery插件/文件。像这样写main.js。我想你失踪的deps。

require.config({
      baseURL: 'scripts',
      paths: {
        jquery: "../../lib/js/zepto/zepto",
        Underscore: "../../lib/js/underscore-amd/underscore",
        Backbone: "../../lib/js/backbone-amd/backbone",
        text: "../../lib/js/requirejs-text/text",
        ChromeExtension: "../chrome-extension",
        Config: "../config",
        Constants: "../constants",
        NotificationService: "notification-service",
        SocketIO: "../../lib/js/socket.io-client/socket.io",
        deffered: "../../lib/js/simply-deffered/deferred",
        PusherClient: "../../lib/js/pusher/pusher.min"
      },
      shim: {
        Constants: {
          deps: ['Config']
        },
        jquery: {
          deps: [],
          exports: '$',
          init: function() {
            return window.jQuery = $;
          }
        },
        Backbone: {
          deps: ['jquery', 'Underscore'],
          exports: 'Backbone'
        },
        Underscore: {
          exports: '_'
        },
        NotificationService: {
          deps: ['SocketIO', 'Backbone']
        },
        deffered: {
          deps: ['jquery'],
          exports: 'Deffered'
        },
        PusherClient: {
          deps: [],
          exports: 'PusherClient'
        }
      }
    });