http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Types-property-DATE
ああ、日付データ型...
とにかく、あなたの質問に答える前に!(日付データ型の例については、tl;dr を参照してください)
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Field-cfg-convert
Reader によって提供された値をモデルに格納されるオブジェクトに変換する関数。次のパラメータが渡されます。
v : 混合
Reader によって読み取られるデータ値。未定義の場合は、構成された defaultValue が使用されます。rec : Ext.data.Model
これまでにリーダーによって読み取られたモデルを含むデータ オブジェクト。フィールドはフィールド配列で定義されている順序で読み取られるため、この時点でモデルが完全に設定されていない可能性があることに注意してください。
Ext.define('Dude', {
extend: 'Ext.data.Model',
fields: [
{name: 'locationInCity', convert: function(rawDataValue,record){
return record.location+', '+record.city //would be something like Sprooklyn,Springfield
}},
{name: 'firstname', mapping: 'name.first'},
{name: 'lastname', mapping: 'name.last'},
{name: 'city', defaultValue: 'homeless'},
'state',
{name: 'location', convert: location}
]
});
ああ、この時点で、あなたの例のソースを見つけました;)
// Add a new Field data type which stores a VELatLong object in the Record.
Ext.data.Types.VELATLONG = {
convert: function(v, data) { // convert(value,record)
return new VELatLong(data.lat, data.long); //VELatLong was declared previously in another library as something according to example
},
sortType: function(v) {
return v.Latitude; // When sorting, order by latitude //VELatLong will have lat and long properties, this is for complex sorting
},
type: 'VELatLong' //This is what we use to reference it.
};
これが行うことは、多かれ少なかれ新しいデータ型を宣言することだけです。それは次のようになります
// Add a new Field data type which stores a VELatLong object in the Record.
Ext.data.Types.tehDate = {
convert: function(v, data) { // convert(value,record)
return new date(v);
},
sortType: function(v) {
return v; // eh i have no idea whether its going to actually just accept date comparisons, though no there's real reason why it shouldn't
},
type: 'tehDate' //This is what we use to reference it.
};
^-- some of this is untested.
TL;DR
実際にあなたの元の質問に答えるために:
Ext DOES には、使用できる日付型があります: Ext.data.Types.DATE (およびその他のいくつか)。
type: date はうまくいかなかったと思います。したがって、適切に参照されているのはおそらく 4 つだけです。しかし!これは機能します:
var types = Ext.data.Types; // allow shorthand type access
Ext.define('Unit', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'dated', type: types.DATE },
{ name: 'pie', type: 'string' },
]
}
});
abc=Ext.create('Unit',{
dated: new Date().toString(),
pie:'hello'
})
console.log(abc)
console.log(abc.get('dated').getUTCFullYear())//it liiiiives!
作業コードのフィドル:
http://www.senchafiddle.com/#w97Oe