var ShapeSizePoolView = Backbone.View.extend({
el : $('#agpb_shape_size_body'),
tmpl : $('#tmpl_agpb_shape_size').html(),
initialize : function() {
this.render();
},
render : function() {
var compiled_template = _.template( this.tmpl, this.model.toJSON() ),
sizes = this.model.get('sizes');
$(this.el).append( compiled_template );
// this is used for our pool sizes
for(var i = 0; i < sizes.length; i++) {
console.log(sizes[i]);
new ShapeSizePoolButtonView(
{
size : sizes[i],
el : $(this.el).find('.agpb_size_list')
});
}
}
});
var ShapeSizePoolButtonView = Backbone.View.extend({
tmpl : $('.tmpl_agpb_shape_size_button').html(),
initialize : function() {
// this.render();
console.log( this.size );
},
render : function() {
var compiled_template = _.template( this.tmpl, this.sizes );
$(this.el).append( compiled_template );
}
});
this.model.get('sizes') 返回一个对象数组。如果我 console.log 在 ShapeSizePoolView 中的一个对象我得到:
{
id: "6",
dimensions: "12'",
price: "649.99",
sort_order: "1"
}
我将此对象传递给一个新视图,但是如果我从 ShapeSizePoolButtonView 中 console.log this.size 我得到:
undefined
有谁知道我哪里出错了?
谢谢!