有一个Bckabone
查看商品:模板切换视图的集合。 Backbone.js的
Product = Backbone.View.extend({
templateBasic: _.template($("#pcard-basic").html()),
templateFull: _.template($("#pcard-full").html()),
initialize: function() {
this.render(this.templateBasic);
},
// ...
这里是我的草案:http://jsfiddle.net/challenger/xQkeP/73
如何隐藏/显示其它视图时,其中一个被选择/未选中,以便查看完整模板,以便它可以扩展到一个完整的容器宽度。
我应该为整个集合使用一个视图吗?我如何处理事件处理?
谢谢!
编辑
这是我的最终草案:http://jsfiddle.net/challenger/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;
}
即时通讯不知道你在问什么。我无法得到你的小提琴的全部意图。 – 2013-02-22 13:11:51
我想显示一个产品视图的集合,其中每个产品视图都可以使用其完整模板进行查看。 – lexeme 2013-02-22 13:20:39
我也在努力理解你的意图。从你的小提琴'showFull'和'showBasic'正在工作。什么不起作用? – juco 2013-02-22 13:29:06