Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I haven't used Backbone.LocalStorage before, and the documentation doesn't specify how you should clear the data, however, in the <a href="https://github.com/jeromegn/Backbone.localStorage/blob/master/backbone.localStorage.js" rel="nofollow">source code</a> there is a <code>_clear()</code> method that should do the trick:</p> <pre><code>function listStore (model, response, options) { searchM.localStorage = new Backbone.LocalStorage("music"); searchM.localStorage._clear(); searchM.save({music: response}, {success: console.log('success') }); </code></pre> <p>As for switching to a new View, that is generally handled using a <a href="http://backbonejs.org/#Router" rel="nofollow">Backbone.Router</a> which will handle redirecting your users to any area of your application you wish.</p> <pre><code>var MyRouter = Backbone.Router.extend({ routes: { "search/:query": "search", // #search/kiwis "page": "page" // #page }, page: function() { new PageView(); //etc... }, search: function(query) { ... } }); //this line is required to tell Backbone that your routes are ready Backbone.history.start(); </code></pre> <p>Once you have the appropriate routes established, you can navigate to the desired location by calling:</p> <pre><code>function listStore (model, response, options) { //check to see if the LS exists, and clear it if so if(searchM.localStorage){ searchM.localStorage._clear(); } searchM.localStorage = new Backbone.LocalStorage("music"); searchM.save({music: response}, {success: console.log('success'); searchM.on('sync', function(){ MyRouter.navigate("page", {trigger: true}); }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload