can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
55 lines (37 loc) • 1.76 kB
Markdown
Map.List
can.Map.plugins
can/map/list
can/map/list/test.html
{2.1} This plugin is pending review and its API has not been finalized. Including this plugin will overwrite [can.List.prototype.filter] (which is faster but doesn't provide live-updating). The new `filter` and `map` methods also have a slightly different API, including the _element_, _index_, and _list_ as arguments (instead of only _element_ and _list_).
The `can.Map.List` plugin adds support for live-updating mapped and filtered observable lists.
`list.filter(callback)`
Generates a new filtered list that live-updates itself to contain the filtered items of the original list.
```
var list = new can.List([
{ name: 'Justin' },
{ name: 'Brian' },
{ name: 'Austin' },
{ name: 'Mihael' }])
// Returns a filtered list that only matches names containing an "n"
var filtered = list.filter(function(element, index, list) {
return item.attr("name").match(/n/i);
});
```
{function(element,index,list)} callback A filtering function that will determine whether an element is filtered or not.
{can.List} A live-updating filtered list.
`list.map(callback)`
Generates a new mapped list that live-updates itself to contain the mapped items of the original list.
```
var list = new can.List([
{ name: 'Justin' },
{ name: 'Brian' },
{ name: 'Austin' },
{ name: 'Mihael' }])
// Returns a mapped list that returns the element names.
var filtered = list.filter(function(element, index, list) {
return item.attr("name");
});
```
{function(element,index,list)} callback A mapping function that will determine each element's mapped value.
{can.List} A live-updating mapped list.
can.