3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.data.Types"></div>/**
16 * @class Ext.data.Types
17 * <p>This is s static class containing the system-supplied data types which may be given to a {@link Ext.data.Field Field}.<p/>
18 * <p>The properties in this class are used as type indicators in the {@link Ext.data.Field Field} class, so to
19 * test whether a Field is of a certain type, compare the {@link Ext.data.Field#type type} property against properties
21 * <p>Developers may add their own application-specific data types to this class. Definition names must be UPPERCASE.
22 * each type definition must contain three properties:</p>
23 * <div class="mdetail-params"><ul>
24 * <li><code>convert</code> : <i>Function</i><div class="sub-desc">A function to convert raw data values from a data block into the data
25 * to be stored in the Field. The function is passed the collowing parameters:
26 * <div class="mdetail-params"><ul>
27 * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader, if undefined will use
28 * the configured <tt>{@link Ext.data.Field#defaultValue defaultValue}</tt>.</div></li>
29 * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.
30 * Depending on the Reader type, this could be an Array ({@link Ext.data.ArrayReader ArrayReader}), an object
31 * ({@link Ext.data.JsonReader JsonReader}), or an XML element ({@link Ext.data.XMLReader XMLReader}).</div></li>
32 * </ul></div></div></li>
33 * <li><code>sortType</code> : <i>Function</i> <div class="sub-desc">A function to convert the stored data into comparable form, as defined by {@link Ext.data.SortTypes}.</div></li>
34 * <li><code>type</code> : <i>String</i> <div class="sub-desc">A textual data type name.</div></li>
36 * <p>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
37 * which contained the properties <code>lat</code> and <code>long</code>, you would define a new data type like this:</p>
39 // Add a new Field data type which stores a VELatLong object in the Record.
40 Ext.data.Types.VELATLONG = {
41 convert: function(v, data) {
42 return new VELatLong(data.lat, data.long);
44 sortType: function(v) {
45 return v.Latitude; // When sorting, order by latitude
50 * <p>Then, when declaring a Record, use <pre><code>
51 var types = Ext.data.Types; // allow shorthand type access
52 UnitRecord = Ext.data.Record.create([
53 { name: 'unitName', mapping: 'UnitName' },
54 { name: 'curSpeed', mapping: 'CurSpeed', type: types.INT },
55 { name: 'latitude', mapping: 'lat', type: types.FLOAT },
56 { name: 'latitude', mapping: 'lat', type: types.FLOAT },
57 { name: 'position', type: types.VELATLONG }
62 Ext.data.Types = new function(){
63 var st = Ext.data.SortTypes;
65 <div id="prop-Ext.data.Types-stripRe"></div>/**
68 * A regular expression for stripping non-numeric characters from a numeric value. Defaults to <tt>/[\$,%]/g</tt>.
69 * This should be overridden for localization.
73 <div id="prop-Ext.data.Types-AUTO"></div>/**
76 * This data type means that no conversion is applied to the raw data before it is placed into a Record.
79 convert: function(v){ return v; },
84 <div id="prop-Ext.data.Types-STRING"></div>/**
87 * This data type means that the raw data is converted into a String before it is placed into a Record.
90 convert: function(v){ return (v === undefined || v === null) ? '' : String(v); },
91 sortType: st.asUCString,
95 <div id="prop-Ext.data.Types-INT"></div>/**
98 * This data type means that the raw data is converted into an integer before it is placed into a Record.
99 * <p>The synonym <code>INTEGER</code> is equivalent.</p>
102 convert: function(v){
103 return v !== undefined && v !== null && v !== '' ?
104 parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10) : 0;
110 <div id="prop-Ext.data.Types-FLOAT"></div>/**
113 * This data type means that the raw data is converted into a number before it is placed into a Record.
114 * <p>The synonym <code>NUMBER</code> is equivalent.</p>
117 convert: function(v){
118 return v !== undefined && v !== null && v !== '' ?
119 parseFloat(String(v).replace(Ext.data.Types.stripRe, ''), 10) : 0;
125 <div id="prop-Ext.data.Types-BOOL"></div>/**
128 * <p>This data type means that the raw data is converted into a boolean before it is placed into
129 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
130 * <p>The synonym <code>BOOLEAN</code> is equivalent.</p>
133 convert: function(v){ return v === true || v === 'true' || v == 1; },
138 <div id="prop-Ext.data.Types-DATE"></div>/**
141 * This data type means that the raw data is converted into a Date before it is placed into a Record.
142 * The date format is specified in the constructor of the {@link Ext.data.Field} to which this type is
146 convert: function(v){
147 var df = this.dateFormat;
155 if(df == 'timestamp'){
156 return new Date(v*1000);
159 return new Date(parseInt(v, 10));
161 return Date.parseDate(v, df);
163 var parsed = Date.parse(v);
164 return parsed ? new Date(parsed) : null;
172 <div id="prop-Ext.data.Types-BOOLEAN"></div>/**
175 * <p>This data type means that the raw data is converted into a boolean before it is placed into
176 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
177 * <p>The synonym <code>BOOL</code> is equivalent.</p>
180 <div id="prop-Ext.data.Types-INTEGER"></div>/**
183 * This data type means that the raw data is converted into an integer before it is placed into a Record.
184 * <p>The synonym <code>INT</code> is equivalent.</p>
187 <div id="prop-Ext.data.Types-NUMBER"></div>/**
190 * This data type means that the raw data is converted into a number before it is placed into a Record.
191 * <p>The synonym <code>FLOAT</code> is equivalent.</p>