2013-10-11 41 views
4

雖然一切看起來不錯,我不能RequireJS使用的航點。 這裏是我的代碼:http://jsfiddle.net/7nGzj/RequireJS +路標:對象的翻譯:有沒有方法「航點」

main.js

requirejs.config({ 
    "baseUrl": "theme/PereOlive/js/lib", 
    "paths": { 
     "app":"../app", 
     "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min" 
    }, 
    "shim": { 
     "waypoints.min": ["jquery"] 
    } 
}); 
requirejs(["app/common"]); 

common.js

define([ 
    'jquery', 
    "waypoints.min", 
], function() { 
    $(function() { 
     console.log($.waypoints); 
     $('#loading').waypoint(function (direction) { 
      // do stuff 
     }); 
    }); 
}); 

我甚至shimed它是確保jQuery是正確加載,但它不」工作。 我的其他圖書館的工作應該像他們(responsiveslides,flexslider,hoverintent,smoothscroll,..)。

  • jQuery的v1.10.2的
  • 路標V2.0.3
  • RequireJS V2.1.8

回答

7

依賴其是AMD-兼容(和路點是)應該經由其註冊模塊名稱是require d 。最簡單的(?只)的方式找出名字是什麼是尋找到lib的源代碼:

// (...) 
if (typeof define === 'function' && define.amd) { 
    return define('waypoints', ['jquery'], function($) { 
    return factory($, root); 
    }); 
} // (...) 

這是「waypoints」!

由於庫是AMD-compatibile,你並不需要一個墊片,但你需要的路徑定義它(因爲文件名可以比AMD模塊名稱不同):

requirejs.config({ 
    "baseUrl": "theme/PereOlive/js/lib", 
    "paths": { 
     "app": "../app", 
     "waypoints": "path/to/waypoints.min" 
    } 
}); 

這樣做之後,你需要改變你require電話:

define([ 
    "jquery", 
    "waypoints" // this is the AMD module name 
] 

修正你的的jsfiddle:http://jsfiddle.net/jVdSk/2/

+0

非常感謝!我一直在尋找幾個小時才能完成工作。 – user2160458

+1

謝謝!你從哪裏學到的? – Tim

相關問題