Backbone Model
HTML
<ul id="result"></ul>
JavaScript
// this example show how to create a backbone model
var Model= Backbone.Model.extend();
// creating an instance that point to our model prototype and setting some attributes
var myModel = new Model({
name : 'foo',
id: 1234,
url: 'com'
});
// you can override or add properties to your models using set method
myModel.set({
surname: 'bar'
});
// convert our model into a JSON file
var modeltoJSON = JSON.stringify( myModel );
myModel.save();
// parsing json obtaining every attribute of our model
JSON.parse( modeltoJSON , function ( key , value ) {
// printing the result just if it is a number or a string
if( ( typeof value === "string" ) || ( typeof value === "number" )) {
$('#result').append( '<li>' + key + ' : ' + value + '</li>');
}
})