2011-09-24 93 views
0
window.NCollection = Backbone.Collection.extend({ 
    url: '/api/all', 
    model: N, 

    parse: function(data){ 
     var that = this; 
     _.each(data, function(item){ 
      switch(item.cat){ 
      case 't1': 
       console.log(new Note(item)); 
       that.add(new Type1(item)); 

       break; 
      case 't2': 
       that.add(new Type2(item)); 
       break; 
      default: 
       that.add(new T(item)); 
      } 
     }); 
    }, 

    nextOrder: function() { 
     if (!this.length) return 1; 
     return this.last().get('id') + 1; 
    }, 

}); 

为什么模型无法添加到集合中?在页面加载时我获取集合的数据。 但收集长度也是0.为什么模型无法添加到BackboneJS集合中

回答

0

而我自己的问题,应该加回来。

parse : function(data) { 
    ............. 
    return data; 
}, 
相关问题