List

  • page
can/map/list
 

Deprecated 2.1

This plugin is pending review and its API has not been finalized. Including this plugin will overwrite 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);
});

Parameters

  1. callback {function(element, index, list)}

    A filtering function that will determine whether an element is filtered or not.

Returns

{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");
});

Parameters

  1. callback {function(element, index, list)}

    A mapping function that will determine each element's mapped value.

Returns

{can.List}

A live-updating mapped list.