1

すべてが完全に実行されていますが、コレクションに新しいアイテムを追加すると、ビューはコレクションを更新して表示しません。ここにコードがあります

App.Views.Contacts = Backbone.View.extend({
    tagName: 'tbody',

    initialize: function(){
        this.collection.on('sync',this.addOne,this);
    },

    render: function(){

        this.collection.each(this.addOne,this);
        return this;
    },

    addOne: function(contact){
        var contactView = new App.Views.Contact({model:contact});
        this.$el.append(contactView.render().el); 
    } 

});

なぜ同期が機能しないのかわかりません

4

1 に答える 1

0

syncイベントですべてのアイテムをレンダリングし、イベントで1つレンダリングする必要があると思いますadd。このような:

initialize: function(){
  this.listenTo(this.collection, 'sync', this.render);
  this.listenTo(this.collection, 'add', this.addOne);
},
于 2013-10-06T19:18:47.963 に答える