0

我敢肯定jqueryunderscore并且backbone在我main.js的工作中require.js。这是我的路由器:

define([
 'jquery',
 'underscore',
 'backbone',
 'views/CartList'
], function($, _, Backbone,CartList){
var AppRouter = Backbone.Router.extend({
    routes: {
        "showCart" : "cartlist"
    }
});
// Initiate the router
var initialize = function(){
    var app_router = new AppRouter;
    app_router.on('cartlist', function(){
        alert(1);
    });
    Backbone.history.start();
};
return {
    initialize: initialize
};
});

这里 app.js :

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

当我浏览www.mysite.com/#showCart时,它没有显示alert.

任何帮助,将不胜感激。

4

1 回答 1

2

尝试添加route:前缀

app_router.on('route:cartlist', function () {
  alert(1);
});
于 2013-09-27T08:13:24.600 回答