Backbone - Log data from ajax call
Backbone - Log data from ajax call
by Nirvanachain
HTML
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
JavaScript
var TheModel = Backbone.Model.extend({
defaults: {
'id': 'null',
'color': '',
'date': '',
'name': ''
}
});
var TheCollection = Backbone.Collection.extend({
models: TheModel,
url: 'https://api.mongolab.com/api/1/databases/testdatabase/collections/Content?apiKey=qcVNgNb-s1X4WJkLeRDfykxqtMG-ezkC'
});
var aCollection = new TheCollection();
var TheView = Backbone.View.extend({
initialize: function () {
this.collection.fetch();
},
render: function () {
console.log('this.collection');
console.log(this.collection);
return this;
}
})
var aView = new TheView({collection: aCollection});
aView.render();