Very basic Backbone/Underscore via Require.js issue driving me batty

后端 未结 5 1285
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 18:35

I am attempting to implement an EXTREMELY basic test that uses jquery, underscore.js and backbone.js loaded via require.js and for some reason I just cannot seem to get everythi

5条回答
  •  野性不改
    2021-01-30 19:24

    I have actually spent a lot of time struggling with this same exact problem!

    Here's how I have managed to get it working...

    First off, download the new sample require-js project with jQuery 1.7. In the zip file you'll find a file called require-jquery.js which includes jQuery 1.7 which is now AMD compliant.

    Then download the latest version of require, which is now also AMD, and last, try this version of Backbone...

    https://github.com/jrburke/backbone/blob/optamd/backbone.js

    Burke has created this off of a fork of backbone and made an AMD compliant version.

    Then...
    Index.htm

    
    
        
            Google Analytics API Browser
            
            
        
        
    
        
    
    

    main.js

    require(['jquery','order!libs/underscore-min','order!libs/backbone','order!scripts/app'], 
    function($,_,Backbone,app){
        app.init();
    });
    

    app.js

    define(['jquery','backbone','scripts/home'], function($, Backbone, router){
        var init = function(){
            console.log("Started");
                // In here you can load your routers/views/whatever
        };
    
        return { init: init};
    });
    

    My file structure looks like
    /app/index.htm
    /app/require-jquery.js
    /app/order.js
    /app/main.js
    /app/text.js
    /app/scripts/app.js
    /app/scripts/home.js
    /app/lib/underscore-min.js
    /app/lib/backbone.js

    Let me know if that helps, hit me up on twitter @jcreamer898 if you need some more help, I am literally working on the same stuff!

    UPDATE I recently created a Github 2 github projects, one an actual app, and another just a simple starter...

    https://github.com/jcreamer898/Savefavs
    https://github.com/jcreamer898/RequireJS-Backbone-Starter

提交回复
热议问题