Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone View Attribute set for next Instantiation?
    text
    copied!<p>I have a view that has a <code>tooltip</code> attribute. I want to set that attribute dynamically on <code>initialize</code> or <code>render</code>. However, when I set it, it appears on the next instantiation of that view instead of the current one:</p> <pre><code> var WorkoutSectionSlide = Parse.View.extend( { tag : 'div', className : 'sectionPreview', attributes : {}, template : _.template(workoutSectionPreviewElement), initialize : function() { // this.setDetailsTooltip(); // doesn't work if run here either }, setDetailsTooltip : function() { // build details ... // set tooltip this.attributes['tooltip'] = details.join(', '); }, render: function() { this.setDetailsTooltip(); // applies to next WorkoutViewSlide // build firstExercises images var firstExercisesHTML = ''; for(key in this.model.workoutExerciseList.models) { // stop after 3 if(key == 3) break; else firstExercisesHTML += '&lt;img src="' + (this.model.workoutExerciseList.models[key].get("finalThumbnail") ? this.model.workoutExerciseList.models[key].get("finalThumbnail").url : Exercise.SRC_NOIMAGE) + '" /&gt;'; } // render the section slide $(this.el).html(this.template({ workoutSection : this.model, firstExercisesHTML : firstExercisesHTML, WorkoutSection : WorkoutSection, Exercise : Exercise })); return this; } }); </code></pre> <p>Here is how I initialize the view:</p> <pre><code>// section preview $('#sectionPreviews').append( (new WorkoutSectionPreview({ model: that.workoutSections[that._renderWorkoutSectionIndex] })).render().el ); </code></pre> <p>How can I dynamically set my <code>attribute</code> (tooltip) on the current view, and why is it affecting the <em>next</em> view?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload