刚接触ext没有多久,碰到这个问题,还望大家不吝赐教啊
从数据库中取出数据以后,放到extjs中的grid 中,用renderer:Ext.util.Format.dateRenderer('Y年m月d日')进行格式化,页面输出结果竟然得到
NaN 年NaN月NaN日
这个怎么解决? 急求答案啊
[b]问题补充:[/b]
刚接触ext,您说的还不太明白,能具体点吗
[b]问题补充:[/b]
[code="java"]
var cm = new Ext.grid.ColumnModel([
{header:'学号',dataIndex:'studentid',sortable:true},
{header:'姓名',dataIndex:'studentname',sortable:true},
{header:'性别',dataIndex:'sex',sortable:true},
{header:'生日',dataIndex:'birthday',sortable:true,renderer :Ext.util.Format.dateRenderer('m/d/Y')},
{header:'班级',dataIndex:'class',sortable:true},
{header:'专业',dataIndex:'discipline',sortable:true},
{header:'籍贯',dataIndex:'address',sortable:true}
]);
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'studentList.action'}),
reader: new Ext.data.JsonReader({
totalProperty : 'totalCount',
root: 'list',
successProperty :'success'
}, [
{name: 'studentid',mapping:'studentid',type:'int'},
{name: 'studentname',mapping:'studentname',type:'string'},
{name: 'sex',mapping:'sex',type:'int'},
{name: 'birthday',mapping:'birthday',type:'date'},
{name: 'class',mapping:'class_',type:'int'},
{name: 'discipline',mapping:'discipline',type:'int'},
{name: 'address',mapping:'address',type:'string'}
])
});
[/code]
[b]问题补充:[/b]
日期格式竟然是 2008-10-23T10:30:00
这是通过json从oracle数据库中取得的
那就应该是 Y-m-d\TH:i:s
试着:
[code="javascript"]
var cm = new Ext.grid.ColumnModel([{
header: '学号',
dataIndex: 'studentid',
sortable: true
},
{
header: '姓名',
dataIndex: 'studentname',
sortable: true
},
{
header: '性别',
dataIndex: 'sex',
sortable: true
},
{
header: '生日',
dataIndex: 'birthday',
sortable: true,
renderer: Ext.util.Format.dateRenderer('Y年m月d日')
},
{
header: '班级',
dataIndex: 'class',
sortable: true
},
{
header: '专业',
dataIndex: 'discipline',
sortable: true
},
{
header: '籍贯',
dataIndex: 'address',
sortable: true
}]);
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'studentList.action'
}),
reader: new Ext.data.JsonReader({
totalProperty: 'totalCount',
root: 'list',
successProperty: 'success'
},
[{
name: 'studentid',
mapping: 'studentid',
type: 'int'
},
{
name: 'studentname',
mapping: 'studentname',
type: 'string'
},
{
name: 'sex',
mapping: 'sex',
type: 'int'
},
{
name: 'birthday',
mapping: 'birthday',
type: 'date',
//2008-10-23T10:30:00
dateFormat:'Y-m-d\TH:i:s'
},
{
name: 'class',
mapping: 'class_',
type: 'int'
},
{
name: 'discipline',
mapping: 'discipline',
type: 'int'
},
{
name: 'address',
mapping: 'address',
type: 'string'
}])
});[/code]
记得定义store中的field
{
name : 'lastChange',
type : 'date',
dateFormat : 'timestamp'
}
则 renderer : Ext.util.Format.dateRenderer('m/d/Y h:i:s A'),
首先,要看你在数据库取出来的时间字符串是怎么样的,
如 2008-10-23 10:30:00
那就要在field的定义中
{name:'myTime',type:'date',dateFormat:[b]'Y-m-d H:i:s'[/b]}
<--这个格式要跟你字符串格式一致, 要Date的api
你发一个你的时间字符串到页面后是什么来看看.
然后在grid的column定义中:
renderer:Ext.util.Format.dateRenderer('H年m月d日')
自己用浏览器访问下studentList.action,把生成的json,拷一条发上来看看