我有一個tooltip
屬性的視圖。我想在initialize
或render
上動態設置該屬性。然而,當我將它,它出現在該視圖,而不是當前的下一個實例:骨幹視圖下一個實例化的屬性集?
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 += '<img src="' +
(this.model.workoutExerciseList.models[key].get("finalThumbnail") ?
this.model.workoutExerciseList.models[key].get("finalThumbnail").url : Exercise.SRC_NOIMAGE) + '" />';
}
// render the section slide
$(this.el).html(this.template({
workoutSection : this.model,
firstExercisesHTML : firstExercisesHTML,
WorkoutSection : WorkoutSection,
Exercise : Exercise
}));
return this;
}
});
這裏是我初始化視圖:
// section preview
$('#sectionPreviews').append(
(new WorkoutSectionPreview({
model: that.workoutSections[that._renderWorkoutSectionIndex]
})).render().el
);
如何動態設置我attribute
(tooltip)就當前視圖而言,爲什麼它會影響下一個視圖?
感謝
這很有道理。不過,我已經更新了我'initialize'到正是和我沒有得到期望的結果:( – Garrett
@Garrett:?什麼是閱讀'attributes'我沒有看到任何訪問它在你的代碼 –
我固定它'這一點。$ el.attr(「提示」,...)',但想知道是否有更好的解決方案。感謝您的見解,我很欣賞你無盡的奉獻SO(和我大部分的問題)。 我使用'attributes'對'el'所以我最終的結果是''