| Package: | CQ.Ext.data |
| Class: | Types |
| Extends: | Object |
| Clientlib: | cq.widgets |
This is s static class containing the system-supplied data types which may be given to a Field.
The properties in this class are used as type indicators in the Field class, so to test whether a Field is of a certain type, compare the type property against properties of this class.
Developers may add their own application-specific data types to this class. Definition names must be UPPERCASE. each type definition must contain three properties:
convert : FunctionsortType : Function type : String For example, to create a VELatLong field (See the Microsoft Bing Mapping API) containing the latitude/longitude value of a datapoint on a map from a JsonReader data block
which contained the properties lat and long, you would define a new data type like this:
// Add a new Field data type which stores a VELatLong object in the Record.
CQ.Ext.data.Types.VELATLONG = {
convert: function(v, data) {
return new VELatLong(data.lat, data.long);
},
sortType: function(v) {
return v.Latitude; // When sorting, order by latitude
},
type: 'VELatLong'
};
Then, when declaring a Record, use
var types = CQ.Ext.data.Types; // allow shorthand type access
UnitRecord = CQ.Ext.data.Record.create([
{ name: 'unitName', mapping: 'UnitName' },
{ name: 'curSpeed', mapping: 'CurSpeed', type: types.INT },
{ name: 'latitude', mapping: 'lat', type: types.FLOAT },
{ name: 'latitude', mapping: 'lat', type: types.FLOAT },
{ name: 'position', type: types.VELATLONG }
]);