.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:



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:



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?


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'
    fields: Ext.calendar.EventRecord.prototype.fields.getRange()

2 个解决方案



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'的屬性,允許您指定確切的日期格式。



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



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