2014-02-21 68 views
0

我想在我的BackboneJS/RequireJS應用程序中使用Lazyload.js插件,但不知道如何做到這一點。任何人都可以提供一個提示嗎?這是我想用lazyload plugin如何在RequireJS和BackboneJS中包含jquery插件

我已經下載了它,並在我的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($){ 
    ... 
}); 

在插件代碼的末尾?

回答

0

我正在複製我的文件..從這裏你可以得到體面的想法如何在骨幹中插入jquery插件/文件。寫這樣的main.js。我認爲你失蹤的代表。

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' 
     } 
     } 
    });