4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-data-Types'>/**
19 </span> * @class Ext.data.Types
20 * <p>This is a static class containing the system-supplied data types which may be given to a {@link Ext.data.Field Field}.<p/>
21 * <p>The properties in this class are used as type indicators in the {@link Ext.data.Field Field} class, so to
22 * test whether a Field is of a certain type, compare the {@link Ext.data.Field#type type} property against properties
23 * of this class.</p>
24 * <p>Developers may add their own application-specific data types to this class. Definition names must be UPPERCASE.
25 * each type definition must contain three properties:</p>
26 * <div class="mdetail-params"><ul>
27 * <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
28 * to be stored in the Field. The function is passed the collowing parameters:
29 * <div class="mdetail-params"><ul>
30 * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader, if undefined will use
31 * the configured <tt>{@link Ext.data.Field#defaultValue defaultValue}</tt>.</div></li>
32 * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.
33 * Depending on the Reader type, this could be an Array ({@link Ext.data.reader.Array ArrayReader}), an object
34 * ({@link Ext.data.reader.Json JsonReader}), or an XML element.</div></li>
35 * </ul></div></div></li>
36 * <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>
37 * <li><code>type</code> : <i>String</i> <div class="sub-desc">A textual data type name.</div></li>
38 * </ul></div>
39 * <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
40 * which contained the properties <code>lat</code> and <code>long</code>, you would define a new data type like this:</p>
41 *<pre><code>
42 // Add a new Field data type which stores a VELatLong object in the Record.
43 Ext.data.Types.VELATLONG = {
44 convert: function(v, data) {
45 return new VELatLong(data.lat, data.long);
47 sortType: function(v) {
48 return v.Latitude; // When sorting, order by latitude
52 </code></pre>
53 * <p>Then, when declaring a Model, use: <pre><code>
54 var types = Ext.data.Types; // allow shorthand type access
56 extend: 'Ext.data.Model',
58 { name: 'unitName', mapping: 'UnitName' },
59 { name: 'curSpeed', mapping: 'CurSpeed', type: types.INT },
60 { name: 'latitude', mapping: 'lat', type: types.FLOAT },
61 { name: 'longitude', mapping: 'long', type: types.FLOAT },
62 { name: 'position', type: types.VELATLONG }
65 </code></pre>
68 Ext.define('Ext.data.Types', {
70 requires: ['Ext.data.SortTypes']
72 var st = Ext.data.SortTypes;
74 Ext.apply(Ext.data.Types, {
75 <span id='Ext-data-Types-property-stripRe'> /**
76 </span> * @property {RegExp} stripRe
77 * A regular expression for stripping non-numeric characters from a numeric value. Defaults to <tt>/[\$,%]/g</tt>.
78 * This should be overridden for localization.
82 <span id='Ext-data-Types-property-AUTO'> /**
83 </span> * @property {Object} AUTO
84 * This data type means that no conversion is applied to the raw data before it is placed into a Record.
87 convert: function(v) {
94 <span id='Ext-data-Types-property-STRING'> /**
95 </span> * @property {Object} STRING
96 * This data type means that the raw data is converted into a String before it is placed into a Record.
99 convert: function(v) {
100 var defaultValue = this.useNull ? null : '';
101 return (v === undefined || v === null) ? defaultValue : String(v);
103 sortType: st.asUCString,
107 <span id='Ext-data-Types-property-INT'> /**
108 </span> * @property {Object} INT
109 * This data type means that the raw data is converted into an integer before it is placed into a Record.
110 * <p>The synonym <code>INTEGER</code> is equivalent.</p>
113 convert: function(v) {
114 return v !== undefined && v !== null && v !== '' ?
115 parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0);
121 <span id='Ext-data-Types-property-FLOAT'> /**
122 </span> * @property {Object} FLOAT
123 * This data type means that the raw data is converted into a number before it is placed into a Record.
124 * <p>The synonym <code>NUMBER</code> is equivalent.</p>
127 convert: function(v) {
128 return v !== undefined && v !== null && v !== '' ?
129 parseFloat(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0);
135 <span id='Ext-data-Types-property-BOOL'> /**
136 </span> * @property {Object} BOOL
137 * <p>This data type means that the raw data is converted into a boolean before it is placed into
138 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
139 * <p>The synonym <code>BOOLEAN</code> is equivalent.</p>
142 convert: function(v) {
143 if (this.useNull && (v === undefined || v === null || v === '')) {
146 return v === true || v === 'true' || v == 1;
152 <span id='Ext-data-Types-property-DATE'> /**
153 </span> * @property {Object} DATE
154 * This data type means that the raw data is converted into a Date before it is placed into a Record.
155 * The date format is specified in the constructor of the {@link Ext.data.Field} to which this type is
159 convert: function(v) {
160 var df = this.dateFormat,
170 if (df == 'timestamp') {
171 return new Date(v*1000);
174 return new Date(parseInt(v, 10));
176 return Ext.Date.parse(v, df);
179 parsed = Date.parse(v);
180 return parsed ? new Date(parsed) : null;
187 Ext.apply(Ext.data.Types, {
188 <span id='Ext-data-Types-property-BOOLEAN'> /**
189 </span> * @property {Object} BOOLEAN
190 * <p>This data type means that the raw data is converted into a boolean before it is placed into
191 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
192 * <p>The synonym <code>BOOL</code> is equivalent.</p>
196 <span id='Ext-data-Types-property-INTEGER'> /**
197 </span> * @property {Object} INTEGER
198 * This data type means that the raw data is converted into an integer before it is placed into a Record.
199 * <p>The synonym <code>INT</code> is equivalent.</p>
203 <span id='Ext-data-Types-property-NUMBER'> /**
204 </span> * @property {Object} NUMBER
205 * This data type means that the raw data is converted into a number before it is placed into a Record.
206 * <p>The synonym <code>FLOAT</code> is equivalent.</p>