Extjs4 中date時間格式的問題


在Grid中顯示時間,后台傳過來的是date格式的數據(PHP date('Y-m-d', time()),一般在Ext model中定義數據的類型和格式:

{name:'birth', type:'date'},

view層:

{ header: '生日', dataIndex: 'birth', editor:{ xtype: 'datefield', format : 'Y-m-d'}}

但這是個可編輯的grid row,通過搜索得知,必須自己定義renderer,試過:

renderer:function(value) {
     if(value instanceof Date) {
      return new Date(value).format('Y-m-d');
    } else {
      return value;
    }
}

在顯示和編輯時候顯示的是 2014-07-15這樣的,但是在編輯狀態為空,編輯完后顯示為“Tue Jul 15 2014 08:00:00 GMT+0800 (中國標准時間)”,顯然不符合。

再搜索,原來還有個util的類,專門是格式化數據的“Ext.util.Format”, view層代碼修改為:

{ header: '生日', dataIndex: 'birth', editor:{ xtype: 'datefield', format : 'Y-m-d'}, renderer:new Ext.util.Format.dateRenderer('Y-m-d')}

即可正確顯示‘Y-m-d’格式的時間。


免責聲明!

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



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