The next part of the self note series, this time I have to parse JSON using backbone.js.
So in order to parse an API that returns result in JSON you can do the following(not necessarily the best way but it works for me)
(function($) {
var API_BASE = 'your url here';
var parser = Backbone.Model.extend({});
var apiColl = Backbone.Collection.extend({
model: parser,
url: 'form your url here'
});
var apiView = Backbone.View.extend({
el: $('#collection'),
initialize: function() {
_.bindAll(this, "render");
this.collection.bind("all", this.count);
},
render: function() {
$(this.el).html(this.counter = this.collection.length);
return this;
}
}),
events = new apiColl(),
eventView = new apiView({
collection: events
});
events.fetch({
success: function() {
console.log(events.length);
}
});
})(jQuery);
and yes, my ultimate target will be to parse the API and integrate with some open maps.
Even though Backbone’s code is pretty well explained, the main help if stuck comes from stack overflow. So really appreciate the help that I got.



















