I want to convert the timestamp to customized date format right after the server returns the data. I tried to use the "convert" in Ext.data.field : http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Field-cfg-convert
But I cannot make it right. This is my model.
Ext.define('AM.model.Comment',{
extend: 'Ext.data.Model',
fields: [
{ name: 'createdTime', type: 'date', convert:function(v,record){record.parseDate(v,record);}}, // datetime
],
proxy: {
type: 'rest',
url:'../comments',
writer:{
type:'json'
},
reader: {
type: 'json'
}
},
parseDate:function(v,record){
console.log(v); //show 1347465600000
console.log(Ext.Date.format(new Date(v), 'Y-m-d')); //show 2012-09-13
return Ext.Date.format(new Date(v), 'Y-m-d');
}
});
After loading, I checked firebug and found the field "createdTime" is "undefined". Can someone point out my mistake? Thanks!
I can achieve that without using "convert", just use Ext.Date.format(new Date(v), 'Y-m-d')
in other component. But I think it will be better to do that in model. Then every component can always read the right date format as querying it.