Ext.Ajax.request( {
url :'../m/Getendtime.jsp',
method :'POST',
params : {
starttime : querystarttime,
user_id : user_id
},
success : function(responseObject) {
var ett = Ext.util.JSON.decode(responseObject.responseText);
ettd = ett['data'];
var etm=Ext.util.Format.date(ettd, "H:i");
}
})
从上面的代码中得到了etm的值,我想把这个值传给timefield(id:et)控件中的maxValue属性,请问该怎么传?
我曾试过在上面代码的最后一句后面加上Ext.getCmp("et").setMaxValue(etm);但是提示timefield没有setMaxValue方法,查阅API后发现timefield确实没有该方法,而datefield有。
[b]问题补充:[/b]
我在程序的开始添加了以下代码
Ext.override( Ext.form.TimeField,
{
setMaxValue: function (time)
{this.maxValue = time;},
getMaxValue: function(){return this.maxValue}
});
然后在使用Ext.getCmp("et").setMaxValue(et)时得不到我要的效果(注:直接使用maxValue:et 可以),使用Ext.getCmp("et").getMaxValue()可以得到我要的时间。为什么??
试下吧,刚写的,我本地测试过的:
[code="javascript"]
function test3(){
Ext.override( Ext.form.TimeField,{
setRangeValue : function(minValue,maxValue){
if(!Ext.isEmpty(minValue)){
this.minValue = this.parseDate(minValue);
}
if(!Ext.isEmpty(maxValue)){
this.maxValue = this.parseDate(maxValue);
}
var min = this.parseDate(this.minValue);
if(!min){
min = new Date(this.initDate).clearTime();
}
var max = this.parseDate(this.maxValue);
if(!max){
max = new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1);
}
var times = [];
while(min <= max){
times.push([min.dateFormat(this.format)]);
min = min.add('mi', this.increment);
}
this.store.loadData(times);
}
});
var t = new Ext.form.TimeField({
minValue: '9:00 AM',
maxValue: '6:00 PM',
increment: 30,
renderTo:document.body
});
var b = new Ext.Button({
renderTo:document.body,
text:'设置结束时间为20:00',
handler:function(){
t.setRangeValue(null,'10:00 PM')
}
})
}
Ext.onReady(test3);
[/code]
你可以通过继承TimeField来增加setMaxValue();
[url]https://www.yui-ext.com/forum/showthread.php?p=339132[/url]
Your override should do the same but with different limits.
[code="java"]
// private
initComponent : function(){
Ext.form.TimeField.superclass.initComponent.call(this);
if(typeof this.minValue == "string"){
this.minValue = this.parseDate(this.minValue);
}
if(typeof this.maxValue == "string"){
this.maxValue = this.parseDate(this.maxValue);
}
if(!this.store){
var min = this.parseDate(this.minValue);
if(!min){
min = new Date(this.initDate).clearTime();
}
var max = this.parseDate(this.maxValue);
if(!max){
max = new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1);
}
var times = [];
while(min <= max){
times.push([min.dateFormat(this.format)]);
min = min.add('mi', this.increment);
}
this.store = new Ext.data.SimpleStore({
fields: ['text'],
data : times
});
this.displayField = 'text';
}
},
[/code]
啊...写错了,不是继承,是重写..
刚在EXTJS FORUM找了下面的代码,人家用了没什么问题,
链接:[url]
https://yui-ext.com/forum/showthread.php?t=52639
[/url]
[code="java"]
Ext.override( Ext.form.TimeField,
{
setMinValue: function (newval)
{
this.minValue = (typeof newval == "string" ? this.parseDate(newval) : newval);
this.setValue(newval);
},
setMaxValue: function (newval)
{
this.maxValue = (typeof newval == "string" ? this.parseDate(newval) : newval);
}
});
[/code]
你看下源码就知道了,
Ext.form.TimeField = Ext.extend(Ext.form.ComboBox
它只在初始化的时候帮你生成一个store,然后根据你给的minValue,maxValue来给store赋值。
你只需要对这个store进行操作就ok了,需要改变的时候就改变store里面的值.
然后可以进一步把改变值的方法封装了,override进去
刚写的一小段,暂时没环境测试,你试下吧.
[code="javascript"]
Ext.override( Ext.form.TimeField,{
setRangeValue : function(minValue,maxValue){
if(!Ext.isEmpty(minValue)){
this.minValue = this.parseDate(minValue);
}
if(!Ext.isEmpty(maxValue)){
this.maxValue = this.parseDate(maxValue);
}
var min = this.parseDate(this.minValue);
if(!min){
min = new Date(this.initDate).clearTime();
}
var max = this.parseDate(this.maxValue);
if(!max){
max = new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1);
}
var times = [];
while(min <= max){
times.push([min.dateFormat(this.format)]);
min = min.add('mi', this.increment);
}
this.store.loadData(times);
}
}
[/code]
setMaxValue(newValue)只是把newValue注入,
而直接maxValue: '8:00 PM',是maxValue属性直接赋值,
而getMaxValue()就直接返回maxValue了,
其实跟JAVA的setter getter方法差不多吧..
在使用Ext.getCmp("et").setMaxValue(et)时得不到我要的效果(注:直接使用maxValue:et 可以),使用Ext.getCmp("et").getMaxValue()可以得到我要的时间。为什么??
都说了,你的setmaxValue只是对那个this.maxValue赋值,而没有去操作store,当然不会改变列表值啦.你按我说的那个overridde就ok了
总结了下:
[url]http://atian25.iteye.com/blog/420313[/url]
这个就是Ext.form.TimeField内部机制的问题了可能