.NET DateTime序列化为JSON以用于ExtJs JsonStore(ExtJs日历的事件存储)?
我正在尝试为ExtJs日历设置Json存储。.NET DateTime序列化为JSON以用于ExtJs JsonStore(ExtJs日历的事件存储)?,json,datetime,serialization,extjs,store,Json,Datetime,Serialization,Extjs,Store,我正在尝试为ExtJs日历设置Json存储。 商店使用Http代理检索其数据。 存储字段包括startDate和endDate,它们是日期类型的对象。 我正在将C#代码中的数据序列化为Json,Http代理将请求Json。 我想知道应该将开始和结束序列化为字符串还是C#DateTime类型。 目前,我正在将它们序列化为DateTime类型 Json响应如下所示: {"Data": "items":[{ "cid":"0", "end":"\/Date(1275260400000+
商店使用Http代理检索其数据。
存储字段包括startDate和endDate,它们是日期类型的对象。
我正在将C#代码中的数据序列化为Json,Http代理将请求Json。
我想知道应该将开始和结束序列化为字符串还是C#DateTime类型。
目前,我正在将它们序列化为DateTime类型 Json响应如下所示:
{"Data":
"items":[{
"cid":"0",
"end":"\/Date(1275260400000+0100)\/",
"notes":"4:00",
"start":"\/Date(1275260400000+0100)\/",
"title":"Basic""}]
fields: [
{ name: 'Id', type: 'int' },
{ name: 'ResourceId', mapping: 'fitter_id', type: 'int' },
{ name: 'StartDate', type: 'date', format: 'd/m/Y G:i' },
{ name: 'EndDate', type: 'date', format: 'd/m/Y G:i' },
{ name: 'status', type: 'int' },
{ name: 'job_id', type: 'int' }
]
开始和结束属性看起来像某种日期引用。
我尝试将startDate和endDate序列化为字符串,而不是DateTime类型。
这将返回以下JsonResponse:
{"Data":
"items":[{
"cid":"0",
"end":"03/06/10",
"notes":"4:00",
"start":"04/06/10",
"title":"Basic""}]
但是,在这两种情况下,当存储完成加载时,endDate和startDate字段都未定义。
我在这里该怎么办?我在想也许我必须把日期格式化成extjs期望的某种格式 下面是一些示例代码:
this.eventStore = new Ext.data.JsonStore({
id: 'eventStore',
root: 'Data.items',
proxy: new Ext.data.HttpProxy({
url: AppRootPath + 'Calendar/GetCalendarData',
method: 'POST'
}),//proxy
fields: Ext.calendar.EventRecord.prototype.fields.getRange()
});
检查文档中的Ext.data.Field-。它有一个名为“dateFormat”的属性,允许您指定确切的日期格式。我遇到了同样的问题,我这样解决了它:
{"Data":
"items":[{
"cid":"0",
"end":"\/Date(1275260400000+0100)\/",
"notes":"4:00",
"start":"\/Date(1275260400000+0100)\/",
"title":"Basic""}]
fields: [
{ name: 'Id', type: 'int' },
{ name: 'ResourceId', mapping: 'fitter_id', type: 'int' },
{ name: 'StartDate', type: 'date', format: 'd/m/Y G:i' },
{ name: 'EndDate', type: 'date', format: 'd/m/Y G:i' },
{ name: 'status', type: 'int' },
{ name: 'job_id', type: 'int' }
]