javascript - backbone and history push state - Stack Overflow

Using backbone, is it any way to store some data in the history so it can be retrived when a back is ca

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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

At 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

相关推荐

  • javascript - backbone and history push state - Stack Overflow

    Using backbone, is it any way to store some data in the history so it can be retrived when a back is ca

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信