Sencha Touch Store With Date Field
I have a Model with Date field and Store which loads from XML with same date field as string. Would the sencha parse it to Date automatically or I would need to do that manually?
Ext.regModel('News', {
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'Title', type: 'string' },
{ name: 'PostedOn', type: 'date' },
{ name: 'PostedBy', type: 'string' },
{ name: 'Details', type: '开发者_开发技巧string' }
]
});
var newsRemoteStore = new Ext.data.Store({
model: 'News',
sorters: [{
property: 'PostedOn',
direction: 'DESC'
}],
proxy: {
type: 'ajax',
url: BaseURL + 'News.php',
reader: {
type: 'xml',
root: 'News',
record: 'New'
}
},
getGroupString: function(record) {
if (record && record.data.PostedOn) {
return record.get('PostedOn').toDateString();
}
else {
return '';
}
}
});
I am asking because the Date field is empty even though there is date in xml response e,g.
<PostedOn>2011-07-04 16:00:19</PostedOn>
Version 1.1 of Sencha Touch supports auto, string, int, float, boolean & date (refer to the Sencha Touch 1.1 API Docs
No, sencha only support 4 data types: int, float, string and auto.
You should set the date field as string and then have it converted in to a date object in the getGroupString to compare it to another date object. Read all about it here: http://www.sencha.com/blog/ext-js-4-anatomy-of-a-model
精彩评论