Answer the question
In order to leave comments, you need to log in
Why is there no information from the collection?
Hello, I am displaying the collection in the backbone, but there is no information from the collection, only default values.
My collection view:
app.Views.contentItemsView = Backbone.View.extend({
initialize: function() {
this.render()
},
render: function(){
this.collection.each(function() {
var contentItemView = new app.Views.contentView({model: app.Global.contentModel})
this.$el.append(contentItemView.el);
}, this);
},
})
app.Global.contentItemsView = new app.Views.contentItemsView({collection: app.Global.contentCollection})
$('.content-list').html(app.Global.contentItemsView.el)
app.Models.content = Backbone.Model.extend({
defaults: {
id: 'Загрузка..',
article: 'Загрузка..',
type:'Загрузка..',
price:'Загрузка..',
about:'Загрузка..'
}
})
app.Global.contentModel = new app.Models.content()
app.Collections.contentCollection = Backbone.Collection.extend({
initialize: function() {
},
model: app.Models.content
})
app.Global.contentCollection = new app.Collections.contentCollection([
{
id: '1..',
article: '1..',
type:'1..',
price:'1..',
about:'1..'
},
{
id: '2..',
article: '2..',
type:'2..',
price:'2..',
about:'2..'
},
{
id: '3..',
article: '3..',
type:'3..',
price:'3..',
about:'3..'
}
])
Answer the question
In order to leave comments, you need to log in
You are iterating over the collection, but you are using data not from the collection, but from xs where:
this.collection.each(function(model) { // передаем аргумент
var contentItemView = new app.Views.contentView({model: model}); // используем его
this.$el.append(contentItemView.el);
}, this);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question