开发者

How to get ExtJS to include timezone when saving record from JsonStore w/ISO 8601 format?

In the snippet below, I am creating a JsonStore (whose record type is a single date field), adding a new record to it, then saving it. When saving, the time zone is not included in the serialized date value, even though it is included with the actual record object (as shown by Firebug). Ext seems to convert the date into the browser's timezone, but then drop the time zone, when sending the request to the server. I am using the ISO 8601 datetime format ('c'), which if I am reading the Ext docs correctly, should include the time zone.

Even if it is converting to the browser's time zone, that wouldn't be a problem for me as long as it includes that time zone when saving the record. As it stands now, the server must be written such that it parses incoming dates in the browser'开发者_Go百科s time zone, but sends them to the client in a possibly different time zone, which seems kludgy. Any suggestions? I read through several seemingly related questions on the Ext forums but they seemed to be dealing with slightly different issues.

var myDataStore = new Ext.data.JsonStore({
    url: '/api/echo',    
    writer: new Ext.data.JsonWriter({
        encode: false,
        writeAllFields: true
    }),
    root: 'records',
    fields: [
        {name: 'myDate', type: 'date', dateFormat: 'c'}
    ],
    autoSave: false,
    autoLoad: false
});

myDataStore.add(new myDataStore.recordType({myDate: Date.parseDate('2010-11-08T11:00:00.000-0000','c')}));
myDataStore.save();

Serialized data (no time zone):

{"records":{"myDate":"2010-11-08T06:00:00"}}


Updating the answer for Ext-JS 4:

Ext.JSON.encodeDate = function(o)
{
   return '"' + Ext.Date.format(o, 'c') + '"';
};


Nevermind, apparently the magic Google phrase was "extjs time zone serialize". This seems to be a known issue. The solution seems fairly simple:

Ext.util.JSON.encodeDate = function(o)
{
   return '"' + o.format('c') + '"';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜