ExtJS笔记 Ext.data.Types

This is a static class containing the system-supplied data types which may be given to a Field.

Types是一个静态类,包含将用在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.

此类中的属性会被用作Field中的类型指示器,因此,如果要测试一个字段是否某个特定类型,可将其type属性与Types类的属性来比较。

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 : Function  转换函数
    A function to convert raw data values from a data block into the data to be stored in the Field. The function is passed the collowing parameters:此函数转数据块中的原始数据到Field字段。函数会被传入两个参数:

    • v : Mixed
      The data value as read by the Reader, if undefined will use the configured defaultValue. 被reader读取的数据,如果未定义则使用defaultValue
    • rec : Mixed
      The data object containing the row as read by the Reader. Depending on the Reader type, this could be an Array (ArrayReader), an object (JsonReader), or an XML element.  reader读取到的当前行数据对象。依赖reader的类型,这可以是一个数组(ArrayReader),对象 (JsonReader),或者xml 元素。
  • sortType : Function  排序类型
    A function to convert the stored data into comparable form, as defined by Ext.data.SortTypes.  一个函数,将数据转换为可比较的形式,详见 Ext.data.SortTypes.

  • type : String  类型
    A textual data type name.   文本形式的类型名称。

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:

例如,我们创建一个VELatLong 字段(参考 Microsoft Bing Mapping API)包含地图上一个数据点的经度/维度值,数据来自JsonReader 的数据块,包含了lat和long属性。对此,你可以定义一个如下的新数据类型:

// Add a new Field data type which stores a VELatLong object in the Record.
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 Model, use:

然后,我们定义一个模型来使用:

var types = Ext.data.Types; // allow shorthand type access
Ext.define('Unit',
    extend: 'Ext.data.Model',
    fields: [
        { name: 'unitName', mapping: 'UnitName' },
        { name: 'curSpeed', mapping: 'CurSpeed', type: types.INT },
        { name: 'latitude', mapping: 'lat', type: types.FLOAT },
        { name: 'longitude', mapping: 'long', type: types.FLOAT },
        { name: 'position', type: types.VELATLONG }
    ]
});

 

数据类型

AUTO : Object

This data type means that no conversion is applied to the raw data before it is placed into a Record.不会发生转换


BOOL : Object
This data type means that the raw data is converted into a boolean before it is placed into a Record. ...   
 
BOOLEAN : Object
This data type means that the raw data is converted into a boolean before it is placed into a Record. ...
 
DATE : Object
This data type means that the raw data is converted into a Date before it is placed into a Record. ...
 
FLOAT : Object
This data type means that the raw data is converted into a number before it is placed into a Record. ...
 
INT : Object
This data type means that the raw data is converted into an integer before it is placed into a Record. ...
 
INTEGER : Object
This data type means that the raw data is converted into an integer before it is placed into a Record. ...
 
NUMBER : Object
This data type means that the raw data is converted into a number before it is placed into a Record. ...
 
STRING : Object

This data type means that the raw data is converted into a String before it is placed into a Record.

 
stripRe : RegExp
A regular expression for stripping non-numeric characters from a numeric value. ...
更多相关文章
  • Ext.data.Store是extjs的数据结构. 主要用于extjs的grid和combobox等控件的数据加载和操作.实际上对grid的增删改可以通过对store的操作来控制. 例子:对grid的增删操作 A.
  • ext.data 最主要的功能是获取和组织数据结构,并和特定控件联系起来,于是,Ext.data成了数据的来源,负责显示数据. Ext.data在命名空间中定义了一系列store.reader和proxy.Grid和ComboxBox都是以Ext.data为媒介获取数据的,它包含异步加载.类型转换.
  • 


    		    extjs 中 Ext.data.Model 的 phantom 属性的讨论
    我使用的extjs版本是4.1.0 ,在Ext.data.Model中, 有一个属性叫phantom,平时不太用到,也没多注意,直到这2天我们team一个js专家遇到一个很棘手的问题,这才触发我去窥测到这个属性的作用. 老习惯,我们还是从需求开始: 需求: 用Extjs的树控件,我们需要在树控件的目 ...
  • 1.record声明如下 machineuse_record = Ext.data.Record.create([{ name : 'id', type : 'int' }, { name : 'projectnam
  • Ext.Loader is the heart of the new dynamic dependency loading capability in Ext JS 4+. It is most commonly used via the Ext.requireshorthand. Ext.Load ...
  • 1.extjs 给怎么给panel设背景色 设置bodyStyle:'background:#ffc;padding:10px;', var resultsPanel = Ext.create('Ext.panel.Panel', { title: 'Results', width: 600, he
  • Using a Proxy Ext.define('User', { extend: 'Ext.data.Model', fields: ['id', 'name', 'email'], proxy: { type: 'rest', url : '/users' } }); 当在Model中定义了一 ...
  • Ext.data.Connection2013年7月24日14:54Ext.data在命名空间中定义了一系列store.reader.proxy,Grid和ComboxBox都是Ext.data为媒介获取数据:并且支
一周排行