ExtJs:将系统日期设置为表单面板中的标签文本
我正在使用ExtJs,我有一个如下的表单ExtJs:将系统日期设置为表单面板中的标签文本,extjs,extjs3,Extjs,Extjs3,我正在使用ExtJs,我有一个如下的表单 var tourPlanForm = new Ext.form.FormPanel({ bodyStyle : { "background-color" : "#000000", "padding" : "10px" }, layout : { type : 'vbox', // pack:'end' align : 'center' }, defaults : { labelWidth : 140,
var tourPlanForm = new Ext.form.FormPanel({
bodyStyle : {
"background-color" : "#000000",
"padding" : "10px"
},
layout : {
type : 'vbox',
// pack:'end'
align : 'center'
},
defaults : {
labelWidth : 140,
padding : '10 0 0 0'
},
items : [ {
xtype : 'compositefield',
labelWidth : 120,
items : [ {
xtype : 'label',
text : 'SystemDate',
forId : 'myFieldId',
style : 'marginleft:10px'
}, ]
}
],
buttons : [ {
text : 'New',
handler : function() {
var sysDate = new Date();
//alert(sysDate);
var lbTourCode = Ext.ComponentQuery.query('form > compositefield > label')[1];
console.log(lbTourCode);
lbTourCode.setText(sysDate);
}
}]
});
我的表单有一个新按钮和一个标签。当用户单击“新建”按钮时,我需要将系统日期设置为标签文本。我用过
var lbTourCode = Ext.ComponentQuery.query('form > compositefield > label')[1];
console.log(lbTourCode);
lbTourCode.setText(sysDate);
但它不起作用。萤火虫控制台说
Ext.ComponentQuery.query('form > compositefield > label')[1]; not define
如果有人能解释一下这个问题的症结所在以及我应该如何克服这个问题,我将不胜感激
谢谢阵列是基于零的,您的物品可能位于:
Ext.ComponentQuery.query('form > compositefield > label')[0]
此外,将itemId
添加到组件可以使以后的查询更容易(在项目数组中还有一个额外的逗号,这可能会在某些浏览器中导致问题):
稍后通过itemId
查询:
var field = Ext.ComponentQuery.query('#myLabelField')[0];
TypeError:Ext.ComponentQuery未定义var tourCode=Ext.ComponentQuery.query(“#idTourCode”)[0];对不起,
Ext.ComponentQuery.query
是4.0。我对Ext 3.0不太熟悉,但根据文档,您可以分配id
(而不是itemId
)并使用Ext.getCmp(“idTourCode”)进行查询。更多信息请访问
var field = Ext.ComponentQuery.query('#myLabelField')[0];