I have a JSON that returns from a REST API the following :
[
{
title: "Block 1",
images: [url1, url2, url3]
},
{
title: "Block 2",
images: [url7, url8, url9]
},
{
title: "Block 3",
images: [url4, url10]
}
]
On the view I want to render URLs so I can show the images on the template, for that I have the below :
index.html
<script id="template" type="text/template">
<img src=<%= images %>>
</script>
Main.js
theView = Backbone.View.extend({
el: $('#mydiv'),
render: function() {
var template = _.template($('#template').html());
var html = template(this.model.toJSON());
this.$el.html(html);
return this;
}
})
fetchFromServ = Backbone.Model.extend({
url: "http://example.com/jsonFile.php"
})
document.addEventListener('DOMContentLoaded', () => {
var fet = new fetchFromServ();
foo = fet.fetch();
var view = new theView({ model: foo });
view.render();
});
So far, here is what I get :
Uncaught TypeError: this.model.get is not a function