I've recently delved into the world of Backbone.js. My goal is to create a Collection and populate it with data sourced externally.
The current format of the data is CSV, not JSON. I am considering converting it to JSON for simplicity.
Therefore, I have two main queries:
- Where should I connect external data to the Collection? It requires a
url
property, but I was planning to fetch data through Ajax without a specific URL in mind. - Is it advisable to convert my data into JSON rather than keeping it in CSV format, and then use the Collection's
url
property for loading?
In an attempt to load data directly into the Collection instead of using the url
property, this code snippet was produced:
var Cat = Backbone.Model.extend({});
var CatCollection = Backbone.Collection.extend({
model: Cat
});
var ajaxData = { 'breed' : 'persian' } // example of external data
var catCollection = new CatCollection(ajaxData);
catCollection.fetch();
However, an error surfaced:
Uncaught Error: A "url" property or function must be specified
.