admin管理员组文章数量:1415697
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
本文标签: javascriptbackbone and history push stateStack Overflow
版权声明:本文标题:javascript - backbone and history push state - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745238761a2649194.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论