Imagine it like this:
{"7B2A9E8D...":{"name":"document","picture":"pictures.jpg","id":"7B2A9E8D..."}}
When using {} you are creating an object...if you use "{}" it becomes a string...but due to multiple double quotes within the string, it results in a syntax error.
UPDATE:
The issue for me lies in the unclear purpose of the extensive code which is supposed to simply save an object into an array :) (thus I'm uncertain about what specific part requires modification). For some quick pointers, here they are:
You currently have this section of code:
var Event = Model.create();
Event.attributes ['name', 'picture'];
var _event = Event.init({name: "document", picture: "images.jpg"});
_event.save();
var json = JSON.stringify(Event.records);
document.write(json);
where you call init() with parameters (an object)...yet if you refer back to your "init" function within Model.js, it doesn't accept any arguments. It would be beneficial to update your init function from this:
init: function(){
var instance = Object.create(this.prototype);
instance.parent = this;
instance.init.apply(instance, arguments);
return instance;
},
to this:
init: function(args){
var instance = Object.create(this.prototype);
instance.parent = this;
instance.init.apply(instance, arguments);
jQuery.extend(instance, args);
return instance;
},
even after making this adjustment, your JSON.stringify
may display incorrect values (only _id) as it struggles to serialize circular references in your JavaScript object. However, your properties remain intact and functional. You can confirm this by editing your code as follows:
var Event = Model.create();
Event.attributes ['name', 'picture'];
var _event = Event.init({name: "document", picture: "images.jpg"});
_event.save();
var json = JSON.stringify(Event.records);
document.write(json);
for(var k in Event.records)
alert(Event.records[k]['picture']);
This will prompt an alert with the "images.jpg" string, indicating that your object, along with its properties, has been successfully saved and is usable (although JSON.stringify may not clearly show it).
I trust this provides assistance in your educational endeavors.