有一个Bckabone
视图产品:
Product = Backbone.View.extend({
templateBasic: _.template($("#pcard-basic").html()),
templateFull: _.template($("#pcard-full").html()),
initialize: function() {
this.render(this.templateBasic);
},
// ...
这是我的草稿:http: //jsfiddle.net/challenge/xQkeP/73
当其中一个被选择/未选择以查看其完整模板时,我如何隐藏/显示其他视图,以便它可以扩展到完整的容器宽度。
我应该为整个集合使用视图吗?我如何处理事件处理?
谢谢!
编辑
这是我的最终草案:http: //jsfiddle.net/challenge/xQkeP/
但是我仍然不确定我是否可以以更优雅的方式实现相同的结果?我只是认为隐藏兄弟姐妹不是解决它的最佳方法:
viewBasic: function(e) {
e.preventDefault();
this.render(this.templateBasic);
if(this.switchedToFull) {
this.$el.siblings().show();
this.switchedToFull = false;
}
},
viewFull: function(e) {
e.preventDefault();
this.render(this.templateFull);
this.$el.siblings().hide();
this.switchedToFull = true;
}