0

コレクションは空ですが、配列が含まれています。コレクションに対して where を実行したいのですが、d モデルが配列 [0] を返すため、これは不可能です。したがって、データはそこにプッシュされません。

私のデータが非同期で生成されているためだと思います

d {models: Array[0], length: 0, _byId: Object, constructor: function, model: function…} _byId: Object _events: Object _idAttr: "id" _listenerId: "l4" length: 15 models: Array[15 ] プロト: e

app.js から

var AppRouter = Backbone.Router.extend({
    routes: {
        "Onderwerpen": "subjectsList"

    },

    initialize: function  () {

        this.categories = new Categories();
        this.categories.getCategoriesFromJSON();

        console.log(this.categories);


        //view for subjectsList
        this.subjectsListView = new SubjectsListView({collection: this.categories});


    },



    subjectsList: function () {
        $('#app').html(this.subjectsListView.render().el);
    },   

});

var app = new AppRouter();

$(function() {
    Backbone.history.start();
});

カテゴリ.jsから

var Categories = Backbone.Collection.extend({
model : Category,
getCategoriesFromJSON : function(){


    var self = this,
        categories = [];

    $.ajax({
        url      : './catalogue.json',
        dataType : 'json'
    }).done(function(data){

        console.log('Catalogue retrieved');

        _.each(data.categories, function( categorieObj ){

            var categorieName       = _.keys(categorieObj)[0],
                categorieAttributes = categorieObj[categorieName];

            categories.push( categorieAttributes );

        });

        //console.log(JSON.stringify(categories));

        self.add( categories );
        self.trigger('reset');
    });
}


});

何が悪いの?

4

1 に答える 1