【问题标题】:Routing in Marionette using a Marionette Object — Can't make it work使用 Marionette 对象在 Marionette 中路由 - 无法使其工作
【发布时间】:2016-01-24 17:32:21
【问题描述】:

我是第一次尝试 Marionette,对它的路由感到非常困惑。

这是我目前所拥有的:一个 Backbone 模型、一个 Backbone 集合、一个 Marionette Layout 视图、一个 Marionette Collection 视图、几个 Marionette Item 视图。视图在 Marionette 对象中连接在一起,如下所示:

var Orchestrator = Marionette.Object.extend({
  initialize: function(layout) {
    this.layout = layout;
    // adding a collection view
    // showing the collection view in the layout view

    // all is honky-dory
  },

  // And here is a test function I want to call when I go to localhost:8080/#test:

  test: function() {
    console.log('HELLOOO!!!');
  }

});

于是混乱就来了。我正在尝试设置路由器:

var Router = Marionette.AppRouter.extend({
  initialize: function(controller) {
    // the 'controller' is an instance of my Orchestrator object defined above
    this.controller = controller;
    console.log(this.controller.test); // the method shows up correctly
    this.appRoutes = {
      'test': 'test'
    };
  }
});

然后我初始化路由器:var router = new Router(orchestrator); 并启动 Marionette 应用程序。

路由器中的 console.log 语句显示 1) 它正在被初始化,2) 'controller' 是正确的 Marionette 对象,并且 3) 'controller' 上有 test 方法。

但是,当我导航到 localhost:8080/#test(我的应用程序在 localhost:8080 提供服务)时,我没有看到任何证据表明 Orchestrator 对象的 test 方法已被调用 - 我的“HELLO”消息不会出现在控制台中。控制台也没有错误。

您能否建议问题可能是什么以及如何解决这个问题?我一直在搜索文档,但到目前为止还没有找到任何答案。

【问题讨论】:

    标签: backbone.js routing marionette


    【解决方案1】:

    天啊!忘记打电话给Backbone.history.start();。骗我!

    【讨论】:

    • 有时你只是忘记启动它:)
    猜你喜欢
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 2016-01-29
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    相关资源
    最近更新 更多