D
D
Danil2015-10-09 16:08:37
JavaScript
Danil, 2015-10-09 16:08:37

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)

My Model:
app.Models.content = Backbone.Model.extend({
    
        defaults: {
            id: 'Загрузка..',
            article: 'Загрузка..',
            type:'Загрузка..',
            price:'Загрузка..',
            about:'Загрузка..'
        }
    })

    app.Global.contentModel = new app.Models.content()

My collection:
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..'
        }
    ])

Where is the error, what is missing?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2015-10-09
@Veneomin

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);

E
Evgeny Petrov, 2015-10-09
@EvgenZZ

try id not string type, but int { id:1, article:'121212'}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question