0

ビューの render メソッドを実行しようとしていますが、何らかの理由で、その理由がよくわかりませんUncaught TypeError: Cannot call method 'listenTo' of undefined

var App = Backbone.View.extend({
    current_election_index: 0,
    el: 'body',
    initialize: function() {
        elections = new Elections();
        _.bindAll(this, 'render');
        this.listenTo(this, 'change', this.render);
        elections.fetch();
/*      elections.fetch({
            success: function(test) {
                console.warn(this.App.render());
                this.render();
            }*/

        // });
    },

    render: function () {
        console.log('this is the render method');
        var view = new ElectionView({model: elections.at(0)})
    }
})
4

1 に答える 1

0

あなたがしたいことは、聞くことelectionsです。this.modelしたがって、またはを聞くのではなくthis

this.listenTo(elections, 'reset', this.render);

resetコレクションのコンテンツ全体が置き換えられたとき」に、コレクションでトリガーされます。イベントは、change「モデルの属性が変更されたときに」モデルでトリガーされます。詳細については、イベントのバックボーンカタログを参照してください。

electionsコレクションに属する各モデルが変更されたときにビューを更新する場合は、ビューElectionViewではなく、必ず各サブビューで更新してくださいApp

于 2013-02-22T17:16:50.223 に答える