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对象之一,我得到:主干:将模型属性传递给视图返回undefined
{
id: "6",
dimensions: "12'",
price: "649.99",
sort_order: "1"
}
我把这个对象传递到一个新的观点,但如果我CONSOLE.LOG this.size从ShapeSizePoolButtonView我得到:
undefined
有没有人有我的错在哪里的想法?
谢谢!
感谢卢卡斯的解释。我想我应该确保我总是阅读手册:)。 – jlonganecker