.NET DateTime序列化為JSON以用於ExtJs JsonStore(ExtJs Calendar的事件存儲)?

[英].NET DateTime serialised to JSON for use in ExtJs JsonStore(event store for ExtJs Calendar)?


I'm trying to set up a Json Store for an ExtJs Calendar.
The store uses a Http Proxy to retrieve it's data.
The stores fields include startDate and endDate which are objects of type date.
I'm serializing data in my C# code into Json which will be requested by the Http proxy.
I am wondering should I serialize the start and endates as a string or as C# DateTime type.
At the moment I am serialising them as DateTime types.

我正在嘗試為ExtJs日歷設置一個Json商店。商店使用Http Proxy來檢索它的數據。 stores字段包括startDate和endDate,它們是date類型的對象。我正在將我的C#代碼中的數據序列化為Json,這將由Http代理請求。我想知道我應該序列化開始並以字符串或C#DateTime類型結束。目前我將它們序列化為DateTime類型。

The Json response looks like this:

Json響應如下所示:

{"Data":
"items":[{
    "cid":"0",
    "end":"\/Date(1275260400000+0100)\/",
    "notes":"4:00",
    "start":"\/Date(1275260400000+0100)\/",
    "title":"Basic""}]

The start and end properties look like some sort of date reference. I have tried serialising the startDate and endDate's as strings rather than DateTime types. This returns the following JsonResponse:

開始和結束屬性看起來像某種日期引用。我嘗試將startDate和endDate序列化為字符串而不是DateTime類型。這將返回以下JsonResponse:

{"Data":
"items":[{
    "cid":"0",
    "end":"03/06/10",
    "notes":"4:00",
    "start":"04/06/10",
    "title":"Basic""}]

However, in both cases when the store has finished loading the endDate and startDate fields are undefined. What should I do here?
I was thinking maybe i have to format the dates into a certain format expected by extjs?

但是,在這兩種情況下,當存儲完成加載時,endDate和startDate字段是未定義的。我該怎么辦?我想也許我必須將日期格式化為extjs預期的某種格式?

Below is some sample code:

以下是一些示例代碼:

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()
});

2 个解决方案

#1


1  

Check the documentation for Ext.data.Field - http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Field . It has a property named 'dateFormat' that allows you to specify the exact date format.

查看Ext.data.Field的文檔 - http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Field。它有一個名為'dateFormat'的屬性,允許您指定確切的日期格式。

#2


0  

I had the same problem and I solved it like this:

我遇到了同樣的問題,我解決了這個問題:

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' }
         ]

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/02/23/725857a580be1e5d5ca952a49008e9ea.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com