我有一个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'所以我最终的结果是''