gpt4 book ai didi

backbone.js - 无法让 Backbone.Router 与 coffeescript 一起工作

转载 作者:行者123 更新时间:2023-12-02 08:48:53 25 4
gpt4 key购买 nike

这让我快发疯了。我无法让简单的路由器工作...

    jQuery ->
class MyRouter extends Backbone.Router
routes:
"" :"index"
"/list" :"showList"
"/item/:id" :"showItem"
index: =>
alert "index"
showList: =>
alert "get the lists"
showItem: (id)=>
alert "the item #{id}"

@app = window ? {}
@app = window.app ? {}
@app.myRouter = MyRouter
Backbone.history.start()

我总是得到这个错误: index.js:50Uncaught TypeError: 无法调用未定义的方法“start”

我看到了这个:Cannot call 'start' of undefined when starting backbone.js history.

但这并没有帮助 =(...

我相信这很容易,但我有点卡在这里......请帮助...

最佳答案

您没有创建 Backbone.Router 的实例,因此 Backbone.history.start() 将失败。

@app.myRouter = new MyRouter()

您发布的链接准确地告诉了您问题所在:

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

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.

关于backbone.js - 无法让 Backbone.Router 与 coffeescript 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10095035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com