2012-03-12 40 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>