无法调用“开始”;启动backbone.js历史记录时未定义。
我在调用时得到 Cannot call 'start' of undefined
...
Backbone.history.start()
运行某些检查时,Backbone 返回对象,但 Backbone.history 返回未定义。
这可能是什么原因造成的?
谢谢
I get Cannot call 'start' of undefined
when calling...
Backbone.history.start()
When running some checks Backbone returns the object but Backbone.history returns undefined.
What could be the cause of this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
控制器上有路由吗? Backbone 仅在至少指定一条路由后创建历史记录。
更多的:
http://tinnedfruit.com/2011/04/26/测试-backbone-apps-with-jasmine-sinon-3.html
Do you have any routes on the controller? Backbone only creates the history once at least one route is specified.
More:
http://tinnedfruit.com/2011/04/26/testing-backbone-apps-with-jasmine-sinon-3.html
我遇到了同样的错误。
当您不创建路由器实例时会发生这种情况:
I hit the same error.
This happens when you do not make an instance of the router:
如果您使用的是 CoffeeScript,并且您的 Router 是使用 CoffeeScript 类关键字和构造函数方法来定义的,请仔细检查您是否在构造函数的定义中调用了 super。这解决了我的 Backbone.history 为空的问题。
If you're using CoffeeScript and your Router is defined using the CoffeeScript class keyword with a constructor method, double check that you invoke super in the definition of the constructor. This resolved the issue of Backbone.history being null for me.
确保在 HTML 头中包含
jQuery.js
beforeunderscore.js
和backbone.js
。Make sure you include
jQuery.js
beforeunderscore.js
andbackbone.js
in HTML head.我由于不同的原因遇到了完全相同的问题,花了几个小时后,我意识到我的路由器“route”中的一个方法:function()导致了这个问题,在我评论这个不必要的额外方法之后,history.start()按预期工作。
I faced exact same issue for different reason, after spending couple of hours i realized that a method in my router "route" : function() is causing the issue, after i comment this unnecessary extra method, history.start() worked as expected.
如果您编写
Backbone.History.start
而不是Backbone.history.start
(正确的是在history
中使用小写的h
)。A similar error message ".. has no method 'start'" pops up if you write
Backbone.History.start
instead ofBackbone.history.start
(the correct one is with lowercaseh
inhistory
).使用旧版本的 jquery 也可能会导致此问题
Also using old versions of jquery could cause this