Ext.data.Types

Hierarchy

Ext.Base
Ext.data.Types

Requires

Files

该类是一个静态类,包含了系统提供的数据类型,并可能被传递到Field中来使用。

在该类中的所有属性,被用于Field类中,作为字段的类型指示器, 如果要测试一个字段Field是否是某一类型, 可以让type属性与该类中的属性进行比较。

开发人员可能会向此类添加他们自己的应用程序中所特定的数据类型。定义的名称必须全部大写。 每个类型定义必须包含三个属性:

  • convert : Function
    要将从一个数据块中原始数据值,进行转换, 将转换的值作为存储在字段中的数据的函数。该函数将通过传递以下参数:
    • v : Mixed
      通过读取器Reader所读取到的数据值,如果返回undefined则将使用 已配置的defaultValue
    • rec : Mixed
      通过读取器Reader所读取到的包含行信息的数据对象。 根据读取器Reader类型,该参数可能是一个Array(ArrayReader), 一个对象(JsonReader),或是一个XML元素。
  • sortType : Function
    一个函数将存储的数据转换为可比较的形式,如同由Ext.data.SortTypes所定义的。
  • type : String
    文本格式的数据类型名称。

例如,若要创建一个 VELatLong 字段(参见 Microsoft Bing Mapping API),在地图上包含了来自一个JsonReader数据块,关于某一数据点的纬度/经度(latitude/longitude)的值, 其中载有latlong属性,若要定义新的数据类型,就像如下所示的:

// 添加一个新的字段数据类型,将一个VELatLong对象存储在记录Record中。
Ext.data.Types.VELATLONG = {
    convert: function(v, data) {
        return new VELatLong(data.lat, data.long);
    },
    sortType: function(v) {
        return v.Latitude;  // 当进行排序时,则根据latitude字段
    },
    type: 'VELatLong'
};

然后,当声明一个模型Model时,采用:

var types = Ext.data.Types; // 允许简写类型访问
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 }
    ]
});
Defined By

Properties

扩展事件

Defaults to: []

Ext.data.Types
AUTO : Object

这种数据类型是指,在数据放入到记录之前,原始数据不进行任何转换直接返回。

这种数据类型是指,在数据放入到记录之前,原始数据不进行任何转换直接返回。

Ext.data.Types
: Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个布尔值返回。 字符串"true"和数值1将被转成布尔值true

同义词BOOLEAN具有同等效力。

Ext.data.Types
: Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个布尔值返回。 字符串"true"和数值1将被转成布尔值true

同义词BOOL具有同等效力。

Ext.data.Types
: Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个日期返回。 这种类型应用于该 Ext.data.Field 的构造函数中所指定的日期格式。

Ext.data.Types
: Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个浮点数返回。

同义词NUMBER具有同等效力。

Ext.data.Types
: Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个整数返回。

同义词INTEGER具有同等效力。

Ext.data.Types
: Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个整数返回。

同义词INT具有同等效力。

Ext.data.Types
: Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个浮点数返回。

同义词FLOAT具有同等效力。

Ext.data.Types
STRING : Object

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个字符串返回。

这种数据类型是指,在数据放入到记录之前,将原始数据转换成一个字符串返回。

本身 获取当前类的引用,此对象被实例化。不同于 statics, this.self是依赖范围,它意味着要使用动态继承。 ...

本身

获取当前类的引用,此对象被实例化。不同于 statics, this.self是依赖范围,它意味着要使用动态继承。 参见 statics 详细对比

Ext.define('My.Cat', {
    statics: {
        speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
    },

    constructor: function() {
        alert(this.self.speciesName); // 依赖 'this'
    },

    clone: function() {
        return new this.self();
    }
});


Ext.define('My.SnowLeopard', {
    extend: 'My.Cat',
    statics: {
        speciesName: 'Snow Leopard'         // My.SnowLeopard.speciesName = 'Snow Leopard'
    }
});

var cat = new My.Cat();                     // alerts 'Cat' 猫
var snowLeopard = new My.SnowLeopard();     // alerts 'Snow Leopard' 雪豹

var clone = snowLeopard.clone();
alert(Ext.getClassName(clone));             // alerts 'My.SnowLeopard'
Ext.data.Types
: RegExp

从一个数值中去除非数字字符的正则表达式。默认为 /[\$,%]/g。 该属性应该被重写为本地化。

Defaults to: /[\$,%]/g

Defined By

Methods

( Object config )private

添加配置

Parameters

Parameters

( Object name, Object member )private

Parameters

( Object xtype )private

添加 Xtype

Parameters

( Array/Arguments ) : Objectdeprecatedprotected
调用原来的方法,这是以前的override重写 Ext.define('My.Cat', { constructor: function() { alert("I'm a cat!"); } }); ...

调用原来的方法,这是以前的override重写

Ext.define('My.Cat', {
    constructor: function() {
        alert("I'm a cat!");
    }
});

My.Cat.override({
    constructor: function() {
        alert("I'm going to be a cat!");

        this.callOverridden();

        alert("Meeeeoooowwww");
    }
});

var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
                          // alerts "I'm a cat!"
                          // alerts "Meeeeoooowwww"

This method has been deprecated since 4.1

版本 使用 callParent 代替.

Parameters

  • : Array/Arguments

    参数的参数,数组或'参数'对象 来自当前方法,例如: this.callOverridden(arguments)

Returns

  • Object

    返回调用重写方法的结果。

( Array/Arguments args ) : Objectprotected

所谓的"parent"方法是指当前的方法。 这是以前的方法派生或重写(参见 Ext.define)。

 Ext.define('My.Base', {
     constructor: function (x) {
         this.x = x;
     },

     statics: {
         method: function (x) {
             return x;
         }
     }
 });

 Ext.define('My.Derived', {
     extend: 'My.Base',

     constructor: function () {
         this.callParent([21]);
     }
 });

 var obj = new My.Derived();

 alert(obj.x);  // alerts 21

这可以用来重写如下:

 Ext.define('My.DerivedOverride', {
     override: 'My.Derived',

     constructor: function (x) {
         this.callParent([x*2]); // 调用原来的My.Derived构造
     }
 });

 var obj = new My.Derived();

 alert(obj.x);  // 现在提示 42

This also works with static methods.

 Ext.define('My.Derived2', {
     extend: 'My.Base',

     statics: {
         method: function (x) {
             return this.callParent([x*2]); // 调用 My.Base.method
         }
     }
 });

 alert(My.Base.method(10);     // alerts 10
 alert(My.Derived2.method(10); // alerts 20

然后,它也可以重写静态方法。

 Ext.define('My.Derived2Override', {
     override: 'My.Derived2',

     statics: {
         method: function (x) {
             return this.callParent([x*2]); // 调用 My.Derived2.method
         }
     }
 });

 alert(My.Derived2.method(10); // 现在提示 40

Parameters

  • args : Array/Arguments

    这个参数, 通过当前方法得到数组或者 arguments 对象, 例如: this.callParent(arguments)

Returns

  • Object

    返回调用父类的方法的结果。

( Object config )private

拓展

Parameters

( Object name )private

得到配置项

Parameters

得到初始化配置项

Parameters

( Object config )private

根据名称判断配置项是否存在

Parameters

( Object config ) : Objectprotected
这个类的初始化配置。典型例子: Ext.define('My.awesome.Class', { // 这是默认配置 config: { name: 'Awesome', isAwes...

这个类的初始化配置。典型例子:

Ext.define('My.awesome.Class', {
    // 这是默认配置
    config: {
        name: 'Awesome',
        isAwesome: true
    },

    constructor: function(config) {
        this.initConfig(config);
    }
});

var awesome = new My.awesome.Class({
    name: 'Super Awesome'
});

alert(awesome.getName()); // 'Super Awesome' 超级棒

Parameters

Returns

  • Object

    mixins 混入原型 键-值对

( Object name, Object mixinClass )private

内部使用混入预处理器(mixins pre-processor)

Parameters

( Object names, Object callback, Object scope )private

更新配置项

Parameters

( Object fn, Object scope )private

扩展事件

Parameters

( Object config, Object applyIfNotSet )private

设置配置项

Parameters

获取从该对象被实例化的类的引用。 请注意不同于 self, this.statics()是独立的作用域,无论this是否运行,总是返回其中的调用类。

Ext.define('My.Cat', {
    statics: {
        totalCreated: 0,
        speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
    },

    constructor: function() {
        var statics = this.statics();

        alert(statics.speciesName);     // 总是等于'Cat',无论'this'是什么,
                                        // 相当于:My.Cat.speciesName

        alert(this.self.speciesName);   // 依赖 'this'

        statics.totalCreated++;
    },

    clone: function() {
        var cloned = new this.self;                      // 依赖 'this'

        cloned.groupName = this.statics().speciesName;   // 相当于: My.Cat.speciesName

        return cloned;
    }
});


Ext.define('My.SnowLeopard', {
    extend: 'My.Cat',

    statics: {
        speciesName: 'Snow Leopard'     // My.SnowLeopard.speciesName = 'Snow Leopard'
    },

    constructor: function() {
        this.callParent();
    }
});

var cat = new My.Cat();                 // alerts 'Cat', 然后提示 'Cat'

var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', 然后提示 'Snow Leopard'

var clone = snowLeopard.clone();
alert(Ext.getClassName(clone));         // alerts 'My.SnowLeopard'
alert(clone.groupName);                 // alerts 'Cat'

alert(My.Cat.totalCreated);             // alerts 3

Returns

配置扩展