Mybonnie1
Mybonnie1
2015-01-22 04:00

ExtJS4 grid日期格式问题

  • extjs4
  • grid
  • 日期格式

grid显示出问题,在网上找了解决办法做了格式转换显示正常了,插入修改都没问题,但是删除数据的时候报错,grid页面上显示的是2001-11-05,但是rec.data获取到的是
Mon Nov 05 2001 00:00:00 GMT+0800 (中国标准时间) 这种格式,怎么解决啊,求助

Field error in object 'book' on field 'date': rejected value [2001-11-05T00:00:00]; codes [typeMismatch.book.date,typeMismatch.date,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [book.date,date]; arguments []; default message [date]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'date'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "2001-11-05T00:00:00"]


Book.del = function (grid, rowIndex, colIndex){
Ext.Msg.confirm("提示","你确定要删除该记录么?",function(confirm){
if("yes" == confirm){
var store = grid.getStore();
var rec = store.getAt(rowIndex);
Ext.Ajax.request({
url:
params:rec.data,
success: function(response){
var text = response.responseText;
var result = Ext.JSON.decode(text);
if(result.success){
Ext.Msg.alert("信息","删除成功");
store.reload();
}else{
Ext.Msg.alert("错误",result.message);
}
}
});
}

});
};


function Todate(v) {
        if(v == null)
        {
          return null;
        }
    var d = new Date();
    var str = v.toString();
    var str1 = str.replace("/Date(", "");
    var str2 = str1.replace(")/", "");
    var dd = parseInt(str2);
    d.setTime(dd);
return d;
  };
Book.store = Ext.create('Ext.data.Store',{
fields:[
'bookName',
'author',
'bookType',
'createBy',
{ name: 'date',type:'date',dateFormat: 'Y-m-d', convert: Todate }
],
proxy: {
type: 'ajax',
url : "bookController.ajax?method=listBook",
reader: {
type: 'json',
root: 'resultList',
totalProperty: 'totalCount'
}
}
});


{
    text:'出版日期',
    dataIndex:'date',
    renderer: Ext.util.Format.dateRenderer('Y-m-d'),
    width:200
}

Book.formPanel = Ext.create('Ext.form.Panel',{
bodyPadding: 10,
defaultType:'textfield',
items:[
{fieldLabel:'书名',name:'bookName',allowBlank:false},
{fieldLabel:'作者',name:'author',allowBlank:false},
{fieldLabel:'书籍类型',name:'bookType',allowBlank:false},
{fieldLabel:'出版日期',name:'date',xtype:'datefield',format:'Y-m-d',allowBlank:false},
new Ext.form.Hidden({name:'_saveType'}),
new Ext.form.Hidden({name:'id'})
]
});


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换