骨干网历史记录开始不起作用 [英] Backbone history start not working

查看:57
本文介绍了骨干网历史记录开始不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从主干开始历史记录,但是出现错误:

I am trying to start history with backbone however I get the error:

无法调用未定义的方法"start"

Cannot call method 'start' of undefined

这里是完整代码的链接: http://pastebin.com/pNsYghgE

Here is a link to the full code : http://pastebin.com/pNsYghgE

在此代码之前,我有jquery,下划线和中枢js,因此我认为这应该根据文档进行.我正在使用骨干0.9.2.我在这里干什么?

I have jquery, underscore, and backbone js include before this code so I would imagine this should work based off the documentation. I am using backbone 0.9.2. What am I doing wring here?

答案

我不想创建路由器的实例,因此在调用Backbone.history.start()之前添加了以下代码:

I want not creating an instance of my routers so I added this code to before I called Backbone.history.start():

//initialize all routes
_(this.modules()).each(function(module, moduleName)
{
    _(module.routers).each(function(router, routerName)
    {
        new router();
    });
});

推荐答案

Backbone.history仅在使用路由定义一个或多个路由器后才能启动:

Backbone.history can only be started after one or more routers have been defined with routes:

http://backbonejs.org/docs/backbone.html#section-113

您可以在此处看到定义路由时创建的Backbone.history对象.我看不到已发布的代码中定义了任何路由器或路由,因此我猜测这是问题所在.

You can see here, that the Backbone.history object is created when routes are defined. I don't see any routers or routes being defined in the posted code, so I'm guessing that this is the problem.

这篇关于骨干网历史记录开始不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆