2013-09-28 57 views
0

我配置main.js文件是這樣的:app.js在Backbone.js的沒有工作+ require.js

requirejs.config({ 
enforceDefine: true, 
paths: { 
    "jquery": "libs/jquery/jquery-min", 
    "underscore": "libs/underscore/underscore-min", 
    "backbone": "libs/backbone/backbone-min" 
}, 
shim: { 
    "underscore": { 
     deps: [], 
     exports: "_" 
    }, 
    "backbone": { 
     deps: ["jquery", "underscore"], 
     exports: "Backbone" 
    } 
} 
}); 

define(["jquery", "underscore", "backbone","reveal"], 
function ($, _, Backbone,Reveal){ 
    console.log("$: " + typeof $); 
    console.log("_: " + typeof _); 
    console.log("Backbone: " + typeof Backbone); 
} 
); 

控制檯是打印出來:

$: function 
_: function 
Backbone: object 

所以我推測,require.js是在我的項目中工作。

這是我在app.js文件所做的:

define(["jquery", "backbone", "router"], function($, Backbone, Router) { 
    $(document).ready(function(){ 
     alert(1); 
    }); 
    var initialize = function(){ 
     Router.initialize(); 
    } 
    return { 
     initialize: initialize 
    }; 
}); 

但警報並未出現在我的瀏覽器我index.html文件,也沒有我的路由器。

任何想法請。謝謝。

+0

你把你的'in – Nothing

回答

0

看起來你沒有在任何地方加載app.js

嘗試加載它在你的main.js

define(["jquery", "underscore", "backbone","reveal", "app"], 
function ($, _, Backbone,Reveal, App){ 
    console.log("$: " + typeof $); 
    console.log("_: " + typeof _); 
    console.log("Backbone: " + typeof Backbone); 
} 
); 
+0

好,它的工作。 – Nothing

相關問題