2012-01-30 55 views
0

我重寫的集合,我取的這樣的parse功能:獲取並解析收藏

parse: function(response) { 
    this.total = response.total; 
    return response.items; 
} 

而且,我已經綁定的集合,使用它的視圖的渲染功能。 this.collection.bind('reset', this.render);

集合本身是集合的初始化函數獲取: this.collection.fetch({ data: params });

收集,然後在子視圖訪問:

render: function() { 
    var catalog, pages; 
    catalog = new App.Views.Catalog({collection: this.collection}); 
    pages = new App.Views.Pages({collection: this.collection}); 

    return this; 
} 

注:

的只有我的方式可以得到它的工作是通過更改綁定到:this.collection.bind('add', this.render);,其結束撥打render四次。

+0

我現在的答案可能不會解決問題。你可以在獲取對象的地方發佈更多的代碼,以及試圖查看'this.total'的值嗎? – 2012-01-30 19:11:46

回答

0

您可能需要將this綁定到渲染函數。更改:

this.collection.bind('reset', this.render); 

要:

this.collection.bind('reset', this.render, this); 
+0

我應該提到我有:'_.bindAll(this,'render')''this.collection.bind('reset',this.render)' – Ari 2012-01-30 21:57:01

+0

OK。你是否介意發佈更多的代碼,特別是在調用了獲取的地方,以及在哪裏可以看到總共未設置的問題? – 2012-01-31 15:15:17