admin管理员组文章数量:1312685
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 ining dates in the browser'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"}}
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 ining dates in the browser'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"}}
Share
Improve this question
asked Nov 8, 2010 at 14:40
Jeff EvansJeff Evans
1,3071 gold badge16 silver badges32 bronze badges
2 Answers
Reset to default 4Updating 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') + '"';
}
本文标签:
版权声明:本文标题:javascript - How to get ExtJS to include timezone when saving record from JsonStore wISO 8601 format? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741907577a2404239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论