【发布时间】:2011-10-11 06:15:41
【问题描述】:
我只是在学习骨干。我有以下
window.ServerList = Backbone.Collection.extend({
model: Server,
cpuTotal: function(){
if (!this.length) return 0;
/*
* NOT SURE HOW TO SUM THEM
* this.get('cpu') is an integer for each of the collections
*/
return this.get('cpu');
}
});
我从这样的视图的渲染方法中调用它
window.AppView = Backbone.View.extend({
// ....
render: function(){
var total_cpu = ServerList.cpuTotal();
var items = ServerList.length;
}
});
变量 total_cpu 始终为空,但 items 始终正确。有什么想法吗?
我知道我的集合正在运行,因为其中有很多项目,但我需要将集合中每个项目的所有 CPU 加起来以作为页面摘要。
对于那些知道 todos 示例 http://documentcloud.github.com/backbone/docs/todos.html 的人,我有一个非常相似的设置。
【问题讨论】: