我是第一次尝试Marionette,对它的路由感到非常困惑。
这是我到目前为止所拥有的:一个主干模型,一个主干集合,一个木偶布局视图,一个木偶集合视图,几个木偶项目视图。视图在一个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'
};
}
});然后初始化Router:var router = new Router(orchestrator);并启动Marionette应用程序。
路由器中的console.log语句显示: 1)它正在被初始化,2)“控制器”是正确的Marionette对象,3)“控制器”上有test方法。
然而,当我导航到localhost:8080/#test (我的应用程序在localhost:8080上提供)时,我没有看到任何证据表明Orchestrator对象的test方法已经被调用-我的'HELLO‘消息没有出现在控制台中。控制台中也没有错误。
你能建议一下可能是什么问题以及如何解决这个问题吗?我一直在搜索文档,但到目前为止还没有找到任何答案。
发布于 2015-10-26 00:47:33
哦!忘了给Backbone.history.start();打电话了。愚蠢的我!
https://stackoverflow.com/questions/33331830
复制相似问题