我已经showCondition
为视图配置中的某些项目指定了自定义属性。如何查询所有这些组件?
我试过Ext.ComponentQuery.query()。问题是,它query()
返回给我正确数量的元素,但没有“真正的”组件,也就是说,当我尝试执行 elements[0].hide() 时,没有任何效果。
我注意到,当我ref
在控制器类中使用相同的元素时,hide()
效果很好。
之后,我已经了解console.log
了两种获取元素的方法的结果,并注意到了奇怪的事情。首先,返回的元素具有不同的 htmlid
属性(textfield-1115
和textfield-1089
)。其次,query()
方法返回的元素已经具有 hidden=true 属性(这就是 hide() 无效的原因)。这两个元素都是textfield
组件。
下面是相关的代码部分。重要的是在onAfterRenderForm()
。
鉴于:
Ext.define('MyApp.view.Test', {
extend: 'Ext.container.Container',
alias: 'widget.test',
layout: 'fit',
initComponent: function() {
Ext.apply(this, {
items: [
{
title: 'form',
itemId: 'myForm',
xtype: 'form',
items: [
{
xtype: 'textfield',
fieldLabel: 'code',
showCondition: 'is-root',
allowBlank: false,
vtype: 'alphanum'
}
]
}
]
});
this.callParent(arguments);
}
});
在控制器中:
Ext.define('MyApp.controller.Test', {
extend: 'Ext.app.Controller',
requires: [
'MyApp.view.Test'
],
refs: [
{
ref: 'codeField', selector: '[showCondition]'
}
],
init: function() {
this.control(
{
'#myForm': {
afterrender: this.onAfterRenderForm
}
);
},
onAfterRenderForm: function(oForm) {
var elements = oForm.query('[showCondition]');
console.log(elements[0]);
console.log(this.getCodeField());
if(elements[0].id == this.getCodeField().id)
alert('Elements are not the same!!!');
}
});