Note that there are some explanatory texts on larger screens.

plurals
  1. PORight way to fetch and retrieve data in Backbone.js
    text
    copied!<p>I’m trying to understand how and where to use data after a fetch using Backbone.js but I’m a little confused.<br/> I’ll explain the situation.<br/> I have an app that, on the startup, get some data from a server. Three different kind of data.<br/> Let’s suppose Airplanes, Bikes, Cars.<br/> To do that, I’ve inserted inside the three collections (Airplanes, Cars, Bikes) the url where to get these data.<br/> I’ve overwrited the parse method, so I can modify the string that I get, order it, and put it in an object and inside localstorage. I need it to be persistent because I need to use those 3 data structure.<br/> So with a fetch i get all those data and put them inside localstorage. Is it correct doing it that way?<br/></p> <p>Now i need to make other calls to the server, like “get the nearest car”.<br/> In the view i need to see the color, name and model of the car, all that informations are inside the object “Cars” in localstorage.<br/> In my view “showcars.view” I just call a non-backbone js, (not a collection, model or view) where i get all the informations i need. In this js i do:</p> <pre><code>var carmodel = new Car(); //car is the backbone model of the cars carmodel.url = '/get/nearest/car'; //that give id of the nearest car carmodel.fetch ({ success: function () {} //here i search the Cars object for a car with the same id //and get name, color, model and put them in sessionstorage }) </code></pre> <p>So after that call, in the view I can get the data I need from the sessionstorage. Is that a bad way of doing things? If so, how i should fetch and analyze those informations? I should do all the calls and operations inside the models?<br/> Thanks</p>
 

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