【发布时间】:2012-09-21 01:19:38
【问题描述】:
假设我有一个big collection,我想将这个大集合的一个子集用于不同的视图。
我尝试了以下代码,但它不起作用,因为 filtered collection 实际上是一个新代码,它不引用 BigCollection instance。
我的问题是:
如何获得属于BigCollection instance 子集的集合?
这是我的代码。请参阅 cmets 了解更多信息:
// bigCollection.js
var BigCollection = Backbone.Collection.extend({
storageName: 'myCollectionStorage',
// some code
});
// firstView.js
var firstView = Marionette.CompositeView.extend({
initialize: function(){
var filtered = bigCollection.where({type: 'todo'});
this.collection = new Backbone.Collection(filtered);
// the issue is about the fact
// this.collection does not refer to bigCollection
// but it is a new one so when I save the data
// it does not save on localStorage.myCollectionStorage
}
});
【问题讨论】:
标签: javascript backbone.js local-storage backbone-views