2012-03-12 43 views
3

我正在嘗試使用Batman.js,我希望將jQuery與它一起用於某些標準的Ajax和動畫功能。與Batman.js一起使用jQuery

我按照位於http://batmanjs.org/download.html的安裝說明進行操作,在頁面底部有一個關於如何使用jQuery適配器的簡短說明,我不太瞭解如何進行設置。

我看到https://github.com/Shopify/batman/tree/master/lib上列出的一些文件,但我不確定他們去哪裏以及如何設置它。任何有關使用jQuery和Batman.js的建議都是正確的。

謝謝。

回答

0

它說,它附帶2(或更多)的文件,其中被命名爲:

batman.js 

batman.jquery.js 

如果你想在你的網站使用jQuery與蝙蝠俠一起,您需要添加包含在batman.jquery.js中的適配器,以便您的<頭部>看起來像:

//disclude the following line, and instead, use batman.jquery.js 
//<script type="text/javascript" src="/path/to/batman.js"></script> 
<script type="text/javascript" src="/path/to/batman.jquery.js"></script> 
<script type="text/javascript" src="/path/to/jquery.js"></script> 

好東西?

+0

感謝您的答覆。這是我曾嘗試的,但我得到一個JS錯誤「未捕獲的ReferenceError:蝙蝠俠沒有定義」,這樣看起來不正確,除非我做了非常非常錯誤的事情。不過謝謝。 – CPrimer 2012-03-12 03:19:31

+0

@ChrisPapadopoulos:原始答案拼寫錯了「javascript」。上面編輯。現在就試試。 – 2012-05-04 19:14:14

+0

有沒有辦法batman.jquery.js而不是batman.js。適配器內幾乎沒有任何代碼。描述必須是錯誤的... batman.jquery.js必須在batman.js之外使用 – Ringo 2012-08-12 08:29:02

1

這裏是我的腳本(獨立的應用程序,而不是軌)的順序est.js包含我的應用程序(這是方便名爲EST):

 <script src="/app/vendor/coffee-script.js" type="text/javascript"></script> 
     <script src="/app/vendor/es5-shim.js" type="text/javascript"></script> 
     <script src="/app/vendor/batman.js" type="text/javascript"></script> 
     <script src="/app/vendor/batman.jquery.js" type="text/javascript"></script> 
     <script src="/app/vendor/jquery-1.7.2.min.js" type="text/javascript"></script> 
     <script src="est.js" type="text/javascript"></script> 

所有的batman lib和jQuery被拉離jquery site

確保正在經過這些執行你的應用程序的運行方式已加載:

<script src="/app/vendor/coffee-script.js" type="text/javascript"></script> 
    <script src="/app/vendor/es5-shim.js" type="text/javascript"></script> 
    <script src="/app/vendor/batman.js" type="text/javascript"></script> 
    <script src="/app/vendor/batman.jquery.js" type="text/javascript"></script> 
    <script src="/app/vendor/jquery-1.7.2.min.js" type="text/javascript"></script> 
    <script src="est.js" type="text/javascript"></script> 

</head> 
    <body> 
    <div id="container" data-yield="main"> 

    </div> 
    </body> 
</html> 

<script type="text/javascript"> 
    EST.run(); 
</script> 

另外,還要確保您的應用在其他窗口類明智的run方法會爆炸:

est.js :

window.EST = class EST extends Batman.App 

    Batman.ViewStore.prefix = 'app/views' 

    # loads up controllers 
    @controller 'app', 'sections', 'sectionrows', 'rows' 
    @model 'section', 'sectionrow', 'row' 

    @root 'app#index' 
    @resources 'sections', 'sectionrows', 'rows' 

    @on 'run', -> 
    console?.log "Running ...." 

    @on 'ready', -> 
    console?.log "EST ready for use." 
1

蝙蝠俠依靠適配器實現Batman.Request並幫助查詢DOM。要使用jQuery使用蝙蝠俠,包括圖書館的Batman.jQuery適配器:

<script src='batman.js'></script> 
<script src='jquery.js'></script> 
<script src='batman.jquery.js'></script> 
<script src='your_app.js'></script> 
<script> 
    YourApp.run() 
</script>