var fs = Ext.create('Ext.form.Panel', {
region : 'north',
frame : true,
bodyStyle : 'padding:4px 2px 3px 4px',
width : document.body.clientWidth,
fieldDefaults : {
labelAlign : 'left',
msgTarget : 'side'
},
items : [ {
xtype : 'container',
anchor : '100%',
layout : 'column',
items : [ {
xtype : 'container',
columnWidth : .2,
layout : 'anchor',
defaultType : 'datefield',
items : {
fieldLabel : '日期',
anchor : '90%',
id:'time',
format : 'Y-m-d',
timePicker : true,
editable : false,
allowBlank : false,
//value : Ext.Date.add(new Date(), Ext.Date.DAY, 1),
listeners : {
'change' : specchangedatefun
}
}
} ]
} ]
});
因爲 value : Ext.Date.add(new Date(), Ext.Date.DAY, 1),
會默認獲取當前瀏覽器所在機器的時間,所以如果用戶主動更改時間的話,會有些許問題
在頁面開始加載的時候 我就先獲取服務器的時間 然後傳到前臺 給前臺的日期控件賦值
Ext.Ajax.request( {
timeout : 3000,
url : 'getdate.action',
success : function(response, config) {
json = Ext.JSON.decode(response.responseText);
var date=new Date(json.date);
var d=Ext.Date.add(date,Ext.Date.DAY, 1)
Ext.getCmp('time').setValue(d);
},
failure : function(response,options) {
}
})//Ajax end
如果遇到出現什麼getFullYear的錯誤的話 可以先把 上面註釋掉的value賦值語句釋放掉,無大礙,頂多就是用瀏覽器的時間先賦值一次 代碼再用服務器的時間來一次