我刚开始尝试在主干网中使用路由器,但我的 Backbone.history.start()
方法不起作用。它给我以下错误
Uncaught TypeError: Cannot call method 'start' of undefined
这是我的代码
(function ($) {
window.App = {
Models: {},
Collections: {},
Views: {},
Router: {}
};
window.Template = function (id) {
return _.template( $('#' + id).html() );
};
App.Router = Backbone.Router.extend({
routers: {
'': 'index'
},
index: function () {
console.log('index page');
}
});
var r = new App.Router;
Backbone.history.start();
})(jQuery);
我怎样才能消除这个错误?
最佳答案
发生这种情况是因为您的路由器中没有任何路由
。
你有 routers
但它不一样 :)
关于javascript - history.start() 函数在 backbone 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14424447/