The can.Map.define plugin allows you to completely control the behavior
of attributes on a can.Map. To use it, you specify
an define object that is a mapping of properties
to attribute definitions. The following example
specifies a Paginate Map:
The can.Map.define plugin not only allows you to define
individual attribute behaviors on a can.Map, but you can also define default
behaviors that would apply to any unspecified attribute. This is particularly
helpful for when you need a particular behavior to apply to every attribute on
a can.Map but won't be certain of what every attribute will be.
The following example is a can.Map that is tied to can.route where only
specified attributes that are serialized will be updated in the location hash:
var State = can.Map.extend({
define: {
foo: {
serialize: true
},
'*': {
serialize: false
}
}
});
var state = new State();
// tie State map to the route
can.route.map(state);
can.route.ready();
state.attr('foo', 'bar');
state.attr('bar', 'baz');
window.location.hash; // -> #!foo=bar
Overview
This plugin is a replacement for the now deprecated attributes and setter plugins. It intends to provide a single place to define the behavior of all the properties of a can.Map.
Here is the cliffnotes version of this plugin. To define...
Use
The can.Map.define plugin allows you to completely control the behavior of attributes on a can.Map. To use it, you specify an define object that is a mapping of properties to attribute definitions. The following example specifies a Paginate Map:
Default behaviors
The can.Map.define plugin not only allows you to define individual attribute behaviors on a can.Map, but you can also define default behaviors that would apply to any unspecified attribute. This is particularly helpful for when you need a particular behavior to apply to every attribute on a can.Map but won't be certain of what every attribute will be.
The following example is a can.Map that is tied to can.route where only specified attributes that are serialized will be updated in the location hash:
Overview
This plugin is a replacement for the now deprecated attributes and setter plugins. It intends to provide a single place to define the behavior of all the properties of a can.Map.
Here is the cliffnotes version of this plugin. To define...
Demo
The following shows picking cars by make / model / year: