How to remake a partial model in the highway?

I have a list of answers as shown below:

enter image description here

each list item is a base model.

{ title: 'answer title...', content: 'answer content...', voteStatus: 'up' } 

When I click on the vote or vote, the voteStatus model will be changed and this response element will be displayed again.

If you have an image in the response content, the image will be re-displayed, but that is not what I want.

How can I just re-display the vote button when I just change the voteStatus ?

+8
templates model
source share
1 answer

You have a subview inside your AnswerView , which is only responsible for displaying the arrows for voting, VotingArrowsView . You must initialize this view inside the initialize AnswerView function, and then add the el view to the el parent view when render parent view:

 var AnswerView = Backbone.View.extend({ initialize: function(options){ this.template = _.template($('#answerTmpl').html()); this.votingArrowsView = new VotingArrowsView({ model: this.model }); ... }, render: function(){ this.$el.html(this.template(this.model.toJSON())); this.$el.prepend(this.votingArrowsView.render().el); return this; }, ... }); var VotingArrowsView = Backbone.View.extend({ initialize: function(options){ this.template = _.template($('#votingArrowsTmpl').html()); this.listenTo(this.model, 'change:voteStatus', this.render); }, render: function(){ this.$el.html(this.template(this.model.toJSON())); return this; } }); 
+7
source share

All Articles