我在ExtJS 3.3.1中注册xtypes时遇到了一些麻烦。
我想要一个包含两个字符串字段的复合字段,但只显示一个。
一些帮助会很好,因为我已经挣扎了很长一段时间,而且我不知道哪些是错的。 这是我的代码:
Ext.myApp.StringDouble = Ext.extend(Ext.form.CompositeField, {
separator: '-',
unitOptions: {},
values: ['first', 'second'],
bothRequired: false,
init: function() {
this.items = [];
var unitConf = {
};
Ext.apply(unitConf, this.unitOptions);
this.items.push(new Ext.form.TextField(Ext.apply({
name: this.values[0] + '.' + this.name,
fieldLabel: this.fieldLabel + ' ' + this.values[0],
value: this.value && this.value[this.values[0]]
}, unitConf)));
this.items.push(new Ext.form.DisplayField({
value: this.separator
}));
this.items.push(new Ext.form.TextField(Ext.apply({
name: this.values[1] + '.' + this.name,
fieldLabel: this.fieldLabel + ' ' + this.values[1],
value: this.value && this.value[this.values[1]]
}, unitConf)));
},
initComponent : function() {
this.init();
Ext.form.TextField.superclass.init.Component.call(this);
}
});
Ext.reg('stringdouble', Ext.myApp.StringDouble);
感谢。
答案 0 :(得分:0)
首先,我不明白为什么在将config传递给compositefield时需要创建自己的组件可以实现相同的行为,就像这样
{
xtype: 'compositefield',
labelWidth: 120
items: [
{
xtype : 'textfield',
fieldLabel: 'Title',
width : 20
},
{
xtype : 'textfield',
fieldLabel: 'First',
flex : 1
}
]
}
并且在调用父类'initComponent方法
时也存在拼写错误initComponent : function() {
this.init();
Ext.form.TextField.superclass.initComponent.call(this);
}