我正在尝试缓存(使用 jQuery 选择器)视图中的一些子元素。
var theView = Backbone.View.extend({
initialize:function(){
this.$subEl = this.$el.find('.sub-el-class');
},
template: Handlebars.compile($('#view-template').html()),
render: function(){
this.$el.html(this.template(this.model.toJSON()));
this.$subEl.hide();
return this;
}
});
当我渲染视图时,$subEl (.sub-el-class) 没有隐藏。每次我必须在 .sub-el-class 元素上做某事时,我宁愿不必使用 jQuery 选择器。
有什么想法不适用于我的代码吗?