gpt4 book ai didi

extjs - 如何在onclick事件中获取表单域的值

转载 作者:行者123 更新时间:2023-12-01 10:10:42 26 4
gpt4 key购买 nike

我正在使用这篇架构的文章http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/

在我的代码中:

我有这个 Application.DashBoardForm.js,我想在 onclick 事件函数中传递 fromdate 的值,如何传递 fromdate 值?

Ext.apply(Ext.form.VTypes, {
daterange : function(val, field) {
var date = field.parseDate(val);

if(!date){
return false;
}
if (field.startDateField) {
var start = Ext.getCmp(field.startDateField);
if (!start.maxValue || (date.getTime() != start.maxValue.getTime())) {
start.setMaxValue(date);
start.validate();
}
}
else if (field.endDateField) {
var end = Ext.getCmp(field.endDateField);
if (!end.minValue || (date.getTime() != end.minValue.getTime())) {
end.setMinValue(date);
end.validate();
}
}
/*
* Always return true since we're only using this vtype to set the
* min/max allowed values (these are tested for after the vtype test)
*/
return true;
}
});

Application.DashBoardForm= Ext.extend(Ext.FormPanel, {
border:false
,initComponent:function() {
var config = {
labelWidth: 125,
frame: true,
title: 'Date Range',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 175},
defaultType: 'datefield',
items: [{
fieldLabel: 'Start Date',
name: 'fromdate',
id: 'fromdate',
vtype: 'daterange',
value : new Date(),
endDateField: 'todate' // id of the end date field
},{
fieldLabel: 'End Date',
name: 'todate',
id: 'todate',
vtype: 'daterange',
value : new Date(),
startDateField: 'fromdate' // id of the start date field
}]
,buttons: [{
text: 'Go',
onClick : function () {
// here i want to access the value of the form field
// how can i access the fromdate value so that i pass it to grid
console.log(this.getForm());
var win = new Ext.Window({
items:{xtype:'DashBoardGrid',fromdate:this}
});
win.show();
}
}]
}; // eo config object

// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));

Application.DashBoardForm.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
// this.store.load();
Application.DashBoardForm.superclass.onRender.apply(this, arguments);
} // eo function onRender
});

Ext.reg('DashBoardForm', Application.DashBoardForm);

如何在 onclick 函数中传递 from date 的值?

最佳答案

由于您为该字段指定了“fromdate”的 ID,因此您可以使用 Ext.getCmp() 引用它并从那里调用它的 getValue() 方法:

var field = Ext.getCmp('fromdate');

var win = new Ext.Window({
items: {
xtype: 'DashBoardGrid',
fromdate: field.getValue()
}
});

关于extjs - 如何在onclick事件中获取表单域的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5374457/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com