Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

HOW TO STORE AND GET DATA FROM JSON FROM BACKBONE.JS

already asked this question (https://teamtreehouse.com/forum/html5-ui-mobile-app-storing-data-in-json), never got answer thoough

Maybe try Stack Overflow instead

3 Answers

Hi Alex, Can you provide with a more elaborated and clear example of what exactly you are trying to do? JSON is just a way to represent data, so by saying 'Get data from Json from Backbone.js' it's not really clear.

Are you working with any REST api that provides you with JSON data? If you are working wtih a REST api, just check the documentation, there are things like .fetch(), .sync() , that allow you to get\store data from\to your server with your backbone.js models.

Or are you trying to just save things like session information? If you just want to save stuff locally as long as the session lives, you can use HTML5 Local Storage - there are some Github solutions for a backbone adapter for the local storage, though I haven't tried them.

Cheers,

Hello Ron. Thanks for your reply. Well basically what I am trying to do is make my local storage data available to other devices and browsers. For instance when i type in notes , they are stored locally and available only from my machine and browser. I would like to use local storage as it is but at the same time make its local storage data available and accessible to all users as if I would be using mysql or other central date store.

Hope u see what i mean

THanks

Hi Alex, Yeah now it's clear - Well, that's not really possible without any database. Any data stored locally with local storage ,session storage or web SQL will be available only locally for the session (the open browser on the specific machine). Any HTML content generated dynamically on your page, is also temporarily on the session only. You would need to set up a data base in order to store content and make it available for other sessions too.

Let's say for example a simple TODO Web App. If I do not have any data base, and I just add new todo's dynamically, they will be deleted when I close the browser - and even if I save them locally they will be available only to me on my browsers session. (like this one exactly: http://todomvc.com/architecture-examples/backbone/) If you notice in this example, they are saving TODO's to the local storage, which means they will be stored locally in my session only. (see their todos.js file)

If I would want this TODO app to be some kind of shared TODO list for anyone who enters it to be able to see my todos, edit them and add new ones - I would have to connect it to a database.

An example with Backbone would be to .fetch() my todoCollection model when the page loads and to .save() any new todo model that is created. Hope this clears things up !

Cheers