English 中文(简体)
难道死灰复一吗?
原标题:Does Backbone.js have a hard dependency on jQuery?

根据骨干网站:

孤身仅是硬性依赖物(和大体;1.3.1)。 对于教育的持久性,历史通过背后支持。 Liner and DOM por with Backbone. 观点包括json2.js和j Query(1.4.2)或Zepto。

I tested with code below, removing jQuery and the Backbone view throws an error.

<html>
<head>
    <title>asda</title>


    <!--<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>-->
    <script src="http://documentcloud.github.com/underscore/underscore.js"></script>
    <script src="http://documentcloud.github.com/backbone/backbone.js"></script>            
    <script type="text/javascript" charset="utf-8" async defer>
        SearchView = Backbone.View.extend({
            initialize: function(){
                alert("Alerts suck.");
            }
        });

        // The initialize function is always called when instantiating a Backbone View.
        // Consider it the constructor of the class.
        var search_view = new SearchView;
    </script>   
</head>
<body>

</body>
</html>

如何战胜。 观点和背后。 1. 路线上不作Qu?

最佳回答

背后。 观点取决于a>。 DOM操纵图书馆,你可以使用不设在某类图书馆的面包.片,你可以把背包裹用来使用你喜欢的任何图书馆。

See the following from the Backbone sources:

// Set the JavaScript library that will be used for DOM manipulation and
// Ajax calls (a.k.a. the `$` variable). By default Backbone will use: jQuery,
// Zepto, or Ender; but the `setDomLibrary()` method lets you inject an
// alternate JavaScript library (or a mock library for testing your views
// outside of a browser).
Backbone.setDomLibrary = function(lib) {
  $ = lib;
};

采用这种方法将使你能够使用你想要的图书馆。

例如:

Backbone.setDomLibrary(myCustomLibrary);
问题回答

您可使用<条码>Backbone。 模型,无标题,但<代码>Backbone。 观点将要求ery或Zepto,就像docs。





相关问题
What s the appropriate granularity for Backbone.js Views?

I m adopting Backbone.js to render a small corner of an existing large web app. If this goes well, I can see Backbone.js growing to encompass the whole of the app, lending some much-needed structure ...

Rendering Layouts with Backbone.js

If you were to build a single page web application (SPWA) using Backbone.js and jQuery with--for example--two controllers that each required a unique page layouts, how would you render the layout? ...

Load html without refresh

Im unsure of how to approach this, should I have the html to be loaded hidden or load it from somewhere? I want to load a form in one page, and dynamic content on other pages. The form can be saved ...

Why are my CoffeeScript/backbone.js events not firing?

I m trying to familiarize myself with CoffeeScript and backbone.js, and I must be missing something. This CoffeeScript: MyView = Backbone.View.extend events: { "click" : "testHandler" ...