http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Types-property-DATE
Oh hey a date data type...
Anyway, before answering your question! ( see the tl;dr for a date data type example )
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Field-cfg-convert
A function which converts the value provided by the Reader into an object that will be stored in the Model. It is passed the following parameters:
v : Mixed
The data value as read by the Reader, if undefined will use the configured defaultValue.
rec : Ext.data.Model
The data object containing the Model as read so far by the Reader. Note that the Model may not be fully populated at this point as the fields are read in the order that they are defined in your fields array.
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}
]
});
Ah and at this point I found the source of your example ;)
// 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.
};
All this does is declare a new data type more or less. it would look something like
// 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
Now to actually answer your -original- question:
Ext DOES have a date type you can use: Ext.data.Types.DATE ( as well as a few others ).
I assume type: date didnt work, else we wouldn't be here! So probably only 4 are referenced properly.
But! this does work:
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!
Fiddle of working code:
http://www.senchafiddle.com/#w97Oe