启动backbone.js 历史记录时无法调用未定义的“开始".

2022-01-24 00:00:00 javascript backbone.js coffeescript

我在调用时得到 Cannot call 'start' of undefined...

I get Cannot call 'start' of undefined when calling...

    Backbone.history.start()

当运行一些检查时,Backbone 返回对象但 Backbone.history 返回未定义.

When running some checks Backbone returns the object but Backbone.history returns undefined.

这可能是什么原因?

谢谢

推荐答案

控制器上有路由吗?Backbone 仅在至少指定一条路由后才创建历史记录.

Do you have any routes on the controller? Backbone only creates the history once at least one route is specified.

更多:

TypeError:无法调用未定义的方法'start'**

TypeError: Cannot call method 'start' of undefined**

嗯,出于某种原因,Backbone.history 未定义,因此没有start 方法就可以了.事实证明,Backbone.js 创建了一个实例Backbone.History(大写H")称为 Backbone.history(小写case ‘h’) 一旦创建了一个控制器,它至少有一个上指定的路线.这是有道理的,因为历史管理只是如果有要响应的路由,则需要.

Hmm, for some reason Backbone.history is undefined, and so there is no start method on it. It turns out that Backbone.js creates an instance of Backbone.History (upper case ‘H’) called Backbone.history (lower case ‘h’) once a controller has been created that has at least one route specified on it. This makes sense, as history management is only required if there are routes to respond to.

http://tinnedfruit.com/2011/04/26/testing-backbone-apps-with-jasmine-sinon-3.html

相关文章