Currently, I am working on developing a new application using Backbone. Unfortunately, the backend APIs have not been written yet, so I am attempting to work with a JSON data file that is local to my project. Setting its location as the urlRoot allows me to fetch it and receive the jqXHR object back. However, I am unsure how to interact with the responseText based on the console.log output of the object.
I came across a similar question regarding Backbone models only returning an object or JSON {readyState : 1}, but it was left unanswered: backbone model is only returning and object, or JSON {readyState : 1}
var JobListings = Backbone.Model.extend({
urlRoot: 'scripts/app/data/listings.json'
});
// Creating an instance of the model
var jobListings = new JobListings();
console.log(jobListings.fetch()); // Returns jqXHR object
console.log(jobListings.attributes); // Returns empty object
How can I access my JSON data? Should it be in a model rather than a collection? I am unclear about the purpose of collections based on other developers' use of them. My understanding was that models hold data while collections are sets of models.
My objective is to create two models for the data - one to handle raw JSON that requires cleaning up, and the second to store the cleaned data for the application's use. Any assistance would be greatly appreciated.
UPDATE:
Here is a snippet of my JSON data... Despite this, I am still struggling to access my data. Do I need to view the data before proceeding?
[
{
"jobId": "1",
"applyUrl": "http://google.com",
"title": "President of the World",
"trackingCode": "1",
"jobDescription": "Stuff",
"requiredSkills": "Stuff",
"requiredExperience": [],
"postingDate": "2013-07-12T11:07:50Z",
"jobLocation": {
"countryCode": "US",
"region": "California",
"municipality": "Santa Monica"
},
"category": "Life",
"businessUnit": [],
"positionType": "Full-Time"
}
]