我无法设置fieldcontainer内的文本框的值。我想为“fieldcontainer”中的“textfield”设置值和其他配置。所以基本上我设置了我从服务器接收到的textfield的配置,例如:allowBank:true,maxlength:4,value:'Hello World'我从服务器获得并想要将其提供给内部的textfield我的自定义控件是fieldcontainer。除了使用内置的textConfig配置值之外,所有其他配置都被应用。以下是我的代码:使用位于fieldcontainer内的配置文件设置文本框的值
Ext.define('PTextField', { extend: 'Ext.form.FieldContainer',
alias: 'widget.ptextfield',
requires: ['Ext.form.TextField', 'Ext.Img'],
width: 170,
fieldLabel: 'Empty Label',
labelAlign: 'top',
layout: {
type: 'hbox'
},
BLANK_IMAGE_URL: '',
constructor: function (config) {
this.callParent(arguments);
Ext.apply(this.down('textfield'), this.textConfig);
Ext.apply(this.down('image'), this.imgConfig);
}, // eo function constructor
initComponent: function() {
var me = this;
this.textBox = this.createTextField();
this.imageBox = this.createImagefield();
this.items = [this.imageBox, this.textBox];
this.callParent(arguments);
}, //eo initComponent
createTextField: function() { return {xtype: 'textfield'} },
createImagefield: function() { return { xtype: 'image', height: 20, width: 20} }
});
var fname = Ext.create('PTextField', {
fieldLabel: 'First Name',
textConfig: { value: 'Hello World', allowBlank: false, readOnly: true, maxLength: 4, width: 100 },
imgConfig: { src: 'http://www.sencha.com/img/20110215-feat-html5.png' }
});
fname.render(Ext.getBody());
我使用的是extjs 4.1。 任何帮助表示赞赏。
为什么使用构造但没有被应用到该领域唯一被应用在其他配置一样allowBlank,最大长度的任何原因就是价值: '你好,世界'。 – nilesh 2012-08-02 13:18:08
您可以使用我的方法放置任何配置。我认为它更简单 – sha 2012-08-02 13:20:09
我想要的构造函数,因为我想在textfield中设置配置(从textConfig形式来的服务器,哪些将来我不知道),所以我不想做像值的映射:me.textConfig.value,用于textfield的所有配置。 – nilesh 2012-08-02 13:26:29