2013-04-09 73 views
1

如何刪除集合中的最後一個模型?刪除Backbone集合中的最後一個模型

 if (this.Collection.models.length < newValue) { 
     console.log('adding'); 
     this.Collection.models.add(); 
     } else { 
     console.log('removing'); 
     // this isnt working, by selecting it by the current collection array index 
     // basically this.Collection.remove([this.Collection.models.length-1]) 
     //this.measuresCollection.models.get('beats').remove(this.measuresCollection.models[i].get('beats')[this.measuresCollection.models[i].get('beats').length]); 
     } 

我不知道ID,所以我只想刪除最後一個。

回答

6

collection.pop([options])

文件:Collection#pop

它低於文檔中的remove方法。它既刪除最後一個模型,也將它返回給你,如果你需要它。如果你只是想刪除它,不要使用返回值。

+1

然後不要得到返回值。它會刪除模型... – Loamhoof 2013-04-09 18:45:33

相關問題