是的我已经包含了不受欢迎的库,我现在绑定了我的loadChisiamo,但我仍然遇到了这个问题。这是main.js
app_start();
var Router = Backbone.Router.extend({
routes: {
"home" : "loadHome",
"chisiamo" : "loadChisiamo",
"*actions": "defaultRoute"
},
initialize: function(){
_.bindAll(this,'loadHome','loadChisiamo');
},
loadHome: function(e){
e.preventDefault();
console.log('loadHome');
var home = new home_view();
},
loadChisiamo: function(e){
e.preventDefault();
console.log('loadChisiamo');
var chiSiamo = new chiSiamo_view();
},
defaultRoute: function(actions) {
}
});
var app_router;
function app_start(){
views();
var topBar = new topbar_view();
var menu = new menu_view();
var home = new home_view();
//app_router = new Router();
Backbone.history.start({ pushState: true });
topBar.render();
menu.render();
home.render();
}
var topbar_view,, menu_view, home_view, chiSiamo_view;
function views() {
topbar_view = Backbone.View.extend({
el: '#header',
template: Handlebars.templates['topbarHome.ht'],
initialize: function() {
_.bindAll(this, "render");
},
render : function() {
this.$el.html(this.template());
}
});
menu_view = Backbone.View.extend({...});
home_view = Backbone.View.extend({...});
chiSiamo_view = Backbone.View.extend({...});
}
现在,一旦我取消注释app_router = new Router()我就会收到此错误'undefined is is a function'。所以这就像我没有定义我的路由器,但我做了上面。那可能是什么问题呢?这是我的index.html
<body>
<div id="container">
<div id='header' class="header"></div>
<div id='main' class="main">
<div id="navigation"></div>
<div id="contain"></div>
</div>
</div>
<script src="scripts/vendor/jquery/jquery.js"></script>
<script src="scripts/vendor/jquery-ui/jquery-ui-1.10.4.min.js"></script>
<script src="scripts/vendor/underscore/underscore-min.js"></script>
<script src="scripts/vendor/backbone/backbone-min.js"></script>
<script src="scripts/vendor/handlebars/handlebars.js"></script>
<script src="scripts/vendor/modernizr/modernizr.custom.js"></script>
<script src="scripts/vendor/plugins/jquery.slides.min.js"></script>
<script src="scripts/templates.js"></script>
<script src="scripts/main.js"></script>
</body>