I have the following router:
appRouter = Backbone.Router.extend({
routes: {
'': 'inbox',
'inbox': 'inbox',
'discussions_engagement': 'contacts',
},
inbox: function(page) {
console.log('inbox');
var page = page || 1;
engage.app.hydrateInbox(page, engage.app.showInbox);
},
....
};
When I am on http://[...]/#inbox and I call
appRouter.navigate('inbox', {trigger: true});
the inbox action doesn't fire which is what I want to achieve. Now I have looked at the source of Backbone (.js#L1027) and I see that it doesn't support what I'm trying to do but is there some way of acplishing this?
I have the following router:
appRouter = Backbone.Router.extend({
routes: {
'': 'inbox',
'inbox': 'inbox',
'discussions_engagement': 'contacts',
},
inbox: function(page) {
console.log('inbox');
var page = page || 1;
engage.app.hydrateInbox(page, engage.app.showInbox);
},
....
};
When I am on http://[...]/#inbox and I call
appRouter.navigate('inbox', {trigger: true});
the inbox action doesn't fire which is what I want to achieve. Now I have looked at the source of Backbone (https://github./documentcloud/backbone/blob/master/backbone.js#L1027) and I see that it doesn't support what I'm trying to do but is there some way of acplishing this?
Share Improve this question asked Feb 25, 2012 at 21:06 Gavin SchulzGavin Schulz 4,7264 gold badges25 silver badges32 bronze badges 1-
1
Not an answer to your question, but maybe a solution (if I get you correctly): (Re-)Render your page / your most parent view, e.g.
appView.render()
. – SunnyRed Commented Feb 25, 2012 at 21:37
3 Answers
Reset to default 4I would create an event manager in your engage.app object, like this:
var vent = _.extend({}, Backbone.Events);
Then in your router do this for the inbox route:
vent.trigger('inbox:show', page);
And handle that event in the engage.app object, doing the code there that used to be in the route handler.
Now, instead of calling appRouter.navigate
you can trigger that same event.
Also, from that handler, you can call appRouter.navigate('inbox');
without passing true. Now you can get your app to the state you want without trying to force the route.
As far as I can tell... As of Backbone 0.9.10 using appRouter.navigate('inbox', {trigger: true});
works as expected.
Another option is just to call the method
appRouter.inbox();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744138222a4560159.html
评论列表(0条)