Skip to main content

Posts

Showing posts from January, 2014

JSON object versus array gotcha

Pulled a little of what's left of my hair out with this little gotcha looking at an issue with Umbraco.I was looking to add a small feature to allow you to re-order a list.  Umbraco (version 7) uses angularjs in the back-office.  Updating this controller and view code was very straightforward to add a couple of buttons to move the list items up and down.  However although I could see the order was properly being saved to the database, the retrieved list remained in the order that the items were created.Using the Chrome console network tab I could see that the JSON response was coming back from the server in the correct order: ... key":"items","value":{"10":"aaa","7":"bbb","8":"ccc"} ... However as soon as this materialised in code, the order was lost: ... key":"items","value":{"7":"bbb","8":"ccc","10":"aaa"} ... T…