admin管理员组文章数量:1402321
I have a Marionette.CompositeView
which needs to render a collection.
I would like to filter this collection on fetch
and add
action.
I tried with the following code (1) but I get the following error (2).
Any ideas, thanks.
(1)
var myCompositeView = Marionette.CompositeView.extend({
initialize: function () {
this.collection = app.taskCollection.where({type: 'todo'});
}
});
(2)
// Uncaught TypeError: Object has no method 'on'
I have a Marionette.CompositeView
which needs to render a collection.
I would like to filter this collection on fetch
and add
action.
I tried with the following code (1) but I get the following error (2).
Any ideas, thanks.
(1)
var myCompositeView = Marionette.CompositeView.extend({
initialize: function () {
this.collection = app.taskCollection.where({type: 'todo'});
}
});
(2)
// Uncaught TypeError: Object has no method 'on'
Share
Improve this question
asked Sep 27, 2012 at 9:18
Lorraine BernardLorraine Bernard
13.5k23 gold badges85 silver badges138 bronze badges
1 Answer
Reset to default 8Marionette's CompositeView and CollectionView both expect the collection
setting to be a valid Backbone.Collection. The where
method on Backbone's collection does not return a Backbone.Collection, it return an array. So you have to wrap a collection around the results:
initialize: function(){
var filtered = app.taskCollection.where({type: 'todo'});
this.collection = new Backbone.Collection(filtered);
}
Of course you can use any type that extends from Backbone.Collection. I just wanted to illustrate the point of it being a collection with this example.
版权声明:本文标题:javascript - The proper way to filter a backbone.collection by using Marionette.CompositeView - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744329477a2600891.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论