I am currently working on integrating with a 3rd-party API that returns an object containing an array.
My goal is to transform this data into a backbone collection and then display it in a view.
I have experimented with different approaches, with my latest attempt looking like this:
var MyCollection = Backbone.Collection.extend({
url: '/api/data',
parse: function (resp) {
return JSON.parse(resp);
},
});
var myCollection = new MyCollection();
myCollection.fetch();
return Backbone.View.extend({
template: _.template(tmpl),
render: function() {
this.$el.html(this.template({
coll: myCollection.toJSON()
}));
return this;
}
However, I am only getting [Object Object] displayed in my template.
When I log the results to the console, I see something like:
YourCollection
[Object]
yourdata.metadata: "www.xyz.edu/"
value: Array[3]
0: Object
Id: "000"
Name: "Name0"
IsValid: True
1: Object
ID: "111"
Name: "name1"
IsValid: True
3: Object
ID: "222"
Name: "name2"
IsValid: True
I would like to separate each element of the array into its own model, but I'm unsure how to achieve this.
Any guidance would be appreciated. Thank you!