简体   繁体   中英

How can I keep sorted Backbone.js collection after going to other URL?

I'm creating an app where Backbone handle table and the data.

The app has a sort and paging view.

The problem right now is, when I sort the collection, and then go to other page. the sorted collection is reset to be unsorted order. I suspect the cause of this is because the paging link brings to other URL #somepage/1 from #somepage/ And backbone will re-fetch the collection.

Is there any feature in backbone to keep the collection after going to other URL? Is it a good practice to go to other page without changing URL?

Thank you

There is a little ambiguity as to what may be going on. Do you mean that you are going to another page using the router?

If the page is being refreshed, then you are probably losing all the information in the collection because everything is being wiped out and completely re-initialized. If this is the case, then you probably want to be using a backbone "Router" .

If you are using Backbone.Router.navigate() to go to another "page" (but in actuality, changing the URL in the browser and modifying its history), then by default, the collection should not be touched unless your code is set up to modify it somehow after that router action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM