title: How to store a "collection" including all models in the local-storage? (backbone.js)
body: <p>I read in a big xml-file in an external <code>fetch()</code> function and this works quiet well. My question is, how could I save the filled collection to a local storage? And how could I test, if the local storage allready exists? Otherwise the <code>fetch()</code> shall be executed.
  Where do I need to add code in collection? <code>save()</code>? <code>localStorage: new Backbone.LocalStorage("test_storage")</code>?</p>
  
  <p>This example shows a small piece of the code:</p>
  
  <pre><code>    var test_collection = Backbone.Collection.extend( .. );
      var test_collection_view = Backbone.View.extend( .. ); 
  
  
      //--------------------------------------
      // external fetch
      //--------------------------------------             
      function fetch(){
         return $.ajax({
             url: 'TestInterface.xml',
                 method: 'GET',
            dataType: 'xml',
            success: function(response_xml) {
  
               ... //parse data to test_collection
  
            }//end success
         });//end ajax
      }//end fetch
  
  
  
      //--------------------------------------
      // Initialize
      //--------------------------------------
      $(document).ready(function(){
  
          $.when( fetch() ).done(function() {            
              var VIEW = new test_collection_view({collection: test_collection});
          });//end when
       });//end ready
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I can also recommend this for further steps with deferred:</p>
  
  <p><a href="https://stackoverflow.com/questions/22015679/return-deferred-promise-object-and-resolve-it">Return deferred promise object and resolve it</a></p>