2013-10-24 43 views
0

我有我的观点:预编译车把模板无法呈现

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; 
    } 
}); 

这是预编译的车把模板:

<h1>Y LOS MODELOS SON</h1> 
<ul> 
{{#each cats}} 
<li> 
{{this}} 
</li> 
{{/each}} 
</ul> 

不过,这并不呈现this.cats阵列; 这不是一个收集问题()我已经修复了一个早期的问题。 感谢您的帮助......

回答

1

你只需要包装的对象在“猫”属性:

this.cats = { cats: _.uniq(cats, false) } 

注意,当您使用{{#each cats}},渲染器将寻找一个财产命名“猫”。你的变量名称是“猫”,但渲染器根本看不到。

Fiddle demo

+0

感谢名单了很多!!!! –