backbone js, Update view on model change

前端 未结 3 1115
挽巷
挽巷 2020-12-25 09:44

Why my view is not getting updated?

    

     
     

        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-25 10:10

    You need to bind your view on model's change. I'm assuming you want to update RowView when a row is updated. I've rewritten your RowView. This will now listen to your model's change.

    var RowView = Backbone.View.extend({  
             events: {
                 "click .age": function() {console.log(this.model.get("name"));}
             },
             initialize: function(){
               this.model.on('change', this.render, this);
             },
             render: function() {
                 var html=_.template(rowTemplate,this.model.toJSON());
                 this.setElement( $(html) );
                 return this;
             },
    
             update : function() {
    
             }
         });
    

提交回复
热议问题