p3drosola / backbone.groupedcollection Goto Github PK
View Code? Open in Web Editor NEWBackbone GroupedCollection is for creating dynamic sub-collections
License: MIT License
Backbone GroupedCollection is for creating dynamic sub-collections
License: MIT License
// removing elements animals.remove(animals.findWhere({name: 'cat'})); grouped_animals.pluck('id'); // ['black', 'green']
On the explanation of 'How does it work?'
In this code is it meant to read the animal as bird instead of cat that is removed?
In GroupedCollection
you only check for close_with
even though it also listens for destroy
events. This is inconsistent with VirtualCollection
where you explicitly checks for both close_with
and destroy_with
and attach the appropriate listeners.
I have a scenario in which I want to create a grouped collection from a real collection, but also apply a filter at the same time. For example, given the following collection:
var tasks = new Backbone.Collection([
{name: 'bob', date: '02-19-2016', task: 'wash dishes'},
{name: 'bob', date: '02-19-2016', task: 'read book'},
{name: 'sally', date: '02-19-2016', task: 'walk the dog'},
{name: 'bob', date: '02-20-2016', task: 'go to gym'},
]);
I want to only get Bob's tasks and group by date. Something like the following would be nice to do:
var groupedTasks = Backbone.buildGroupedCollection({
collection: tasks,
groupBy: function (task) {
return task.get('date');
},
vc_options: {
filter: function(task) {
return task.get('name') === 'bob';
}
}
});
I looked around the code, and I think the reason why this doesn't work is because any filter options are overridden from this code.
My current solution is to first create a virtual collection with the filter I want, then pass it in as the collection for the grouped collection:
var virtualCollection = Backbone.VirtualCollection(tasks, {
filter: function(task) {
return task.get('name') === 'bob';
}
});
var groupedTasks = Backbone.buildGroupedCollection({
collection: virtualCollection,
groupBy: function (task) {
return task.get('date');
}
});
Going to play around with this over the weekend, but figured I should raise an issue in case others are running into this.
Hello pedro,
I discovered your VirtualCollection recently when I was actually searching for a solution for grouping my collections, so I'm amazed again, that you already have a solution ready.
Or at least a part of my solution..
I'm trying to allow the user to group the collection by different properties, which the user can select. However, then I'd like to group the resulting items again per group, based on a different property.
So, for instance I'd like to group my shopping list by shops, and then again by item type, so I can quickly find all things that are in one place.
Is this possible? If so, how would you recommend going about implementing this?
Unlike Backbone.VirtualCollection, I can't seem to find this package on NPM. Has it been published?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.