我有我的看法:
var ProductsView = Backbone.View.extend({
initialize: function(){
var that = this;
this.collection.fetch({
success: function()
{
console.log("fetcheo");
that.render();
}
});
this.listenTo(this.collection, "reset", this.render);
},
render: function(){
var cats = [];
this.collection.each(function(model)
{
cats.push(model.get('familia'));
});
this.cats = _.uniq(cats, false);
console.log(this.cats) // It returns ["VINOS", "CERVEZA", "BOTANA"]
this.$el.html(Handlebars.templates.products(this.cats));
return this;
}
});
这是预编译的 Handlebar 模板:
<h1>Y LOS MODELOS SON</h1>
<ul>
{{#each cats}}
<li>
{{this}}
</li>
{{/each}}
</ul>
但它没有渲染 this.cats 数组;这不是收集问题(),我已经解决了一个早期问题。谢谢您的帮助...