1

КI have metadata.json on my server.

{
    "type":    "list",
    "columns": 2,
    "buttons": [
        "jobs",
        "agencies",
        "career_guide",
        "livelihood_guide"
    ]
}

It is sort of self construction navigation. The buttons property is actually a folders which contain the same file with other description.

The problem is when I Ctrl+F5 or Command+R (hard refresh) in the browser, those buttons listed in correct order. But when I click button then back, I mean start navigating the order is changed until I refresh the page again.

How I can make sure the order is the same? I need the order exactly like it is entered in json file.

Sergey Romanov
  • 2,949
  • 4
  • 23
  • 38

1 Answers1

2

You should consider expanding the button array of strings to an array of objects. If each entry becomes an object with an order value and a name you can guarantee that the display order is exact. You could either create these objects server-side when you build the JSON, or in your controller before you put the buttons into $scope.

orderBy sorts numerically and alphabetically out-of-the-box; neither of which satisfy your ordering requirements. Implementing an order identifier will allow you to take advantage of the orderBy method. Here's a fiddle of what I'm suggesting.

Sam Berry
  • 7,394
  • 6
  • 40
  • 58
  • Can I just change JSON file to `"buttons": {"key1":"jobs","key2":"agencies","key3":"career_guide","key4":"livelihood_guide"}`? – Sergey Romanov Jun 05 '14 at 11:05
  • 1
    `orderBy` only supports arrays, so if you would like to use an object instead you will have to write your own filter. [Something like this](http://stackoverflow.com/a/18186947/1756430). – Sam Berry Jun 05 '14 at 12:42