Trunk: call advanced view function with overridden render ()

I have a WorkoutExerciseRowView that continues with ExerciseRowView . The rendering functions are very similar, except for WorkoutExerciseRowView you need to add several parameters to the ExerciseRowView render. How can I call the ExerciseRowView render function inside the WorkoutExerciseRowView display WorkoutExerciseRowView ?

 var WorkoutExerciseRowView = ExerciseRowView.extend( { render : function() { //return this.constructor.render({ // doesn't work return this.render({ // doesn't work workoutExercise : this.model, exercise : this.model.get("exercise"), workoutSection : this.model.get("section"), isEditable : true, number : this.number, WorkoutExercise : WorkoutExercise, WorkoutSection : WorkoutSection }); } }); 

Thanks!

+6
source share
3 answers
 var WorkoutExerciseRowView = ExerciseRowView.extend( { render : function() { return ExerciseRowView.prototype.render.call(this,{ workoutExercise : this.model, exercise : this.model.get("exercise"), workoutSection : this.model.get("section"), isEditable : true, number : this.number, WorkoutExercise : WorkoutExercise, WorkoutSection : WorkoutSection }); } }); 

From the basic documentation here: http://backbonejs.org/#Model-extend

Briefly about super: JavaScript does not provide an easy way to call super - a function with the same name that was defined above on the prototype circuit. If you override the main function, for example, set, or save, and you want to call the implementation of the parent object, you will have to explicitly call it this way:

Backbone.Model.prototype.set.call(this, attributes, options);

+14
source

You should be able to use

 ExerciseRowView.prototype.render.call(this) 

This will call the render function from ExerciseRowView with the scope set for this (current model)

+7
source
 this.constructor.__super__.render.call(this,{}); 
+1
source

Source: https://habr.com/ru/post/919087/


All Articles