0
Моя коллекция не получает данные с URL-адреса. Консоль сообщает {length: 0, models: Array [0], _byId: Object}. JSON определенно существует, в противном случае он вызывает ошибку. Что мне не хватает?Коллекция Backbone.js не получает данные с url
JS:
$(document).ready(function(){
// Model
var Article = Backbone.Model.extend({
defaults: {
title: '',
body: ''
}
});
// Collection
var Articles = Backbone.Collection.extend({
model: Article,
url: 'http://local.headless.com/apps/test.json'
});
// View
var ArticlesView = Backbone.View.extend({
el: $("#article-container"),
initialize: function(){
this.collection = new Articles;
this.collection.fetch();
console.log(this.collection); // Nothing here
this.render();
},
render: function(){
//var template = _.template($("#article-template").html(), {});
//this.$el.html(template(this.collection.toJSON()));
},
});
var articleView = new ArticlesView();
});
JSON:
[{"title":"<a href=\"\/node\/2\" hreflang=\"en\">Basic Page 2<\/a>","body":"<p>This is basic page 2<\/p>"},{"title":"<a href=\"\/node\/1\" hreflang=\"en\">This is a basic page<\/a>","body":"<p>This is the content for basic page 1<\/p>"}]