Backbone.js 使用木偶对象在木偶中布线—;Can';我做不到
我第一次尝试木偶,对它的路线感到非常困惑 这里是我到目前为止所拥有的:一个主干模型,一个主干集合,一个木偶布局视图,一个木偶集合视图,一对木偶项目视图。视图在木偶对象中连接在一起,如下所示:Backbone.js 使用木偶对象在木偶中布线—;Can';我做不到,backbone.js,routing,marionette,Backbone.js,Routing,Marionette,我第一次尝试木偶,对它的路线感到非常困惑 这里是我到目前为止所拥有的:一个主干模型,一个主干集合,一个木偶布局视图,一个木偶集合视图,一对木偶项目视图。视图在木偶对象中连接在一起,如下所示: var Orchestrator = Marionette.Object.extend({ initialize: function(layout) { this.layout = layout; // adding a collection view // showing th
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路由器=新路由器(orchestrator)编码>并启动木偶应用程序
路由器中的console.log
语句显示1)它正在初始化,2)控制器是正确的木偶对象,3)控制器上有方法test
但是,当我导航到localhost:8080/#test
(我的应用程序在localhost:8080
)时,我没有看到任何证据表明Orchestrator
对象的测试方法已被调用-我的“HELLO”消息没有出现在控制台中。控制台中也没有错误
你能告诉我可能是什么问题以及如何解决吗?我一直在搜索文档,但到目前为止还没有找到任何答案 D'oh!忘记调用主干.history.start()代码>。愚蠢的我 有时你只是忘记启动它:)