serialize
can.Map.prototype.define.serialize
Called when an attribute is removed.
serialize( currentValue )
Parameters
-
value
{*}
The current value of the attribute.
-
attr
{String}
The name of the attribute being serialized.
Returns
{* | undefined}
If undefined
is returned, the value is not serialized.
This
{can.Map}
The map instance being serialized.
Use
serialize is useful for serializing a can.Map instance into a more JSON-friendly form. This can be used for many reasons, including saving a can.Model instance on the server or serializing map's internal can.Map for display in the hash or pushstate URL.
The serialize property allows an opportunity to define how each attribute will behave when the map is serialized. This can be useful for:
The following causes a locationIds property to be serialized into the comma separated ID values of the location property on this map:
Returning
undefined
for any property means this property will not be part of the serialized object. For example, if the property numPages is not greater than zero, the following example won't include it in the serialized object.