Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:18:11+00:00 2026-06-03T01:18:11+00:00

I’m making a Backbone app now and using a backbone.localstorage plugin to persist the

  • 0

I’m making a Backbone app now and using a backbone.localstorage plugin to persist the data. My app has some sortable items so I hope every time I sort the items, the data order in localStorage will also change. And next time I refresh the whole page, the page will be rendered by the sorted data. But it seems that backbone.localstorage will persist the data in its creation order. Could someone give me some ideas on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:18:13+00:00Added an answer on June 3, 2026 at 1:18 am

    If you want your models to appear in an explicit order then include a comparator in your collection and, possibly, a position number in each model.

    Local storage is:

    a means through which string key/value pairs can be securely stored and later retrieved for use.

    Note the key/value pairs, that means that you’re dealing with, more or less, a big hash table and those are usually unordered. Furthermore, from the fine specification:

    The order of keys is user-agent defined, but must be consistent within an object so long as the number of keys doesn’t change. (Thus, adding or removing a key may change the order of the keys, but merely changing the value of an existing key must not.)

    So there is no particular order inside local storage. If you want a specific order, you have to arrange for it yourself.

    In your case, you’d probably have a position or index property in your models that would behave like an array index; then, in your collection:

    comparator: function(m) { return m.get('position') } // or 'index'
    

    You could also use a two argument comparator function:

    comparator: function(a, b) {
        a = a.get('position');
        b = b.get('position');
        if(a < b)
            return -1;
        else if(a > b)
            return 1;
        return 0;
    }
    

    You’d have to maintain the position indexes as you move models around but that shouldn’t be terribly difficult. You could also order the data by position after pulling it out of local storage but before putting it in your collection and then assign position values while writing the models into local storage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.