Extjs4處理json日期和時間


 

當ASP.NET后台使用JavaScriptSerializer這個組件將對象序列化為json,

            Hashtable ht = new Hashtable();//生成一個哈希表
            ht.Add("total", listu.Count);//保存數據總數
            ht.Add("rows", listu);//數據list對象

            JavaScriptSerializer jss = new JavaScriptSerializer();//.net 3.5自帶的
        JsonStr = jss.Serialize(ht);//序列化為json
            context.Response.Write(JsonStr);//輸出json

生成的日期json格式是這樣的//Date(1213718400000+0800)//

這種格式ExtJs不識別,導致Grid上無法正常顯示。使用ExtJS4的時候,在列模式里像下面這樣處理即可。

 1 {
 2     text:'審核時間',
 3     dataIndex:'VALID_DATE',
 4     width:200,
 5     renderer: function(value) { 
 6         if(value){
 7             var dt=eval("new " + value.substr(1, value.length - 2)).toString();
 8         return Ext.util.Format.date(dt, "Y年m月d日H時i分s秒");//"Y年m月d日H時i分s秒" 
 9                  
10         }     
11        }
12 }

 當ASP.NET后台使用Newtonsoft.Json(JSON.NET)這個組件將對象序列化為json,

            Hashtable ht = new Hashtable();
            ht.Add("total", listu.Count);
            ht.Add("rows", listu);

            JsonStr = JsonConvert.SerializeObject(ht);//使用json.net序列化
        context.Response.Write(JsonStr);

 生成的日期格式是標准的日期像這樣子:

"2013-01-15T15:00:00"
{
    text:'審核時間',
    dataIndex:'VALID_DATE',
    width:200,
    xtype:'datecolumn',
    format:'Y年m月d日H時i分s秒'
}

 最終前台顯示結果一樣,

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM