Using backbone, is it any way to store some data in the history so it can be retrived when a back is called?
In a none backbone application I the application will be something like the following. When executing an action:
//When doing some action
history.pushState(mycurrentData, title, href)
and the following to retvive the current Data in case of back:
function popState(event) {
if (event.state) {
state = event.state;
//get my data from state
}
}
window.onpopstate = popState;
I need to apply the same behaviour on my backbone app.
Thanks
Using backbone, is it any way to store some data in the history so it can be retrived when a back is called?
In a none backbone application I the application will be something like the following. When executing an action:
//When doing some action
history.pushState(mycurrentData, title, href)
and the following to retvive the current Data in case of back:
function popState(event) {
if (event.state) {
state = event.state;
//get my data from state
}
}
window.onpopstate = popState;
I need to apply the same behaviour on my backbone app.
Thanks
Share Improve this question asked May 10, 2012 at 8:43 MateuMateu 2,6986 gold badges38 silver badges56 bronze badges1 Answer
Reset to default 6At this point, it's not possible with Backbone directly
http://backbonejs/docs/backbone.html#section-139
You can see a couple of lines down at that point in the code:
window.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, frag);
So, it's setting the data to an empty object, all the time.
To make this work, then, you'd have to store the data on your own and use some other method of retrieving the data when your route fires.
Personally, I think it would be worth patching Backbone to allow data storage in the history. But that's a thought for the Backbone issues list :)
EDIT
It looks like someone else wanted to do this and it was shot down: https://github./documentcloud/backbone/pull/660
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745238761a4618048.html
评论列表(0条)