我应该如何使用路由器进行此操作?
var itemView = Marionette.ItemView.extend({
events: {
'click #loadPage': 'loadPage'
},
loadPage: function () {
document.location.hash = '#tasks/' + this.model.get('id');
}
});
我应该如何使用路由器进行此操作?
var itemView = Marionette.ItemView.extend({
events: {
'click #loadPage': 'loadPage'
},
loadPage: function () {
document.location.hash = '#tasks/' + this.model.get('id');
}
});
根据文档,router.navigate 只是代理到 Backbone.history,它是全局的,因此您应该能够毫无问题地使用它:
Backbone.history.navigate("#tasks/", { trigger: true })
预期的{trigger: true}
选项将触发哈希更改,以便您的路由器可以在注册该路由时做出反应。
您必须具有带有路由器实例的“全局”变量。
然后以这种方式调用该变量:
// yourRouter was defined in your main controller like this:
// var YourRouterClass = Backbone.Router.extend({
// stuff of your own Router
// });
// var yourRouter = new YourRouterClass(); <- this is your global router instance
yourRouter.navigate('tasks/'+this.model.get('id'), {trigger : true});