can.Model.List
inherits: can.List
A list connected to can.Model's CRUD abilities.
new can.Model.List( [models] )
new can.Model.List( params )
Create an initially empty model list, but use the model's findAll to get a list of models and add it to this empty list.
Parameters
-
params
{Object}Params that are passed to the Map property's findAll method.
Use
can.Model.Listis a can.List associated with a can.Model.can.Model.Lists are just like can.List except they have a few super-powers:findAll).Defining a model list
When can.Model is extended,
can.Model.Listis automatically extended and set as that model's List property. Typically, acan.Model.Listis defined for you. For example:This List type is returned by findAll:
The List's Map property points to the extended can.Model:
Defining custom
can.Model.Listsallows you to extend lists with helper functions for a list of a specific type. The following adds the ability to retrieve the number of completed and remaining todos:Creating a model list instance
If you use findAll, it calls back with and resolves to a model list:
Create a model list yourself, use
new {model_name}.List(ARRAY)like:If objects are provided, model list will convert them to models. The following does the same thing as the previous example:
If a model list is created with a plain JavaScript object like:
The object is assumed to be parameters to the list's Model's findAll method. An empty list will be returned, but
Todo.findAllwill be called. The items it returns will be inserted into the list.Removing models from model list
One advantage that
can.Model.Listhas over a traditionalcan.Listis that when you destroy a model, if it is in that list, it will automatically be removed from the list.