1

フィールドコンテナ内にあるテキストフィールドの値を設定できません。「フィールドコンテナ」内にある「テキストフィールド」の値とその他の構成を設定したい。したがって、基本的には、サーバーから受け取るテキストフィールドの構成を次のように設定します:フィールドコンテナである私のカスタムコントロール。組み込みの textConfig を使用する値 config を除いて、他のすべての構成が適用されます。以下は私のコードです:

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を使用しています。どんな助けでも大歓迎です。

4

2 に答える 2

1

設定を使用してテキストフィールドと画像を作成するだけです。次に、作成したオブジェクトを使用して、次のようにアイテム配列を定義します。

initComponent: function() { 
    var me = this,
        textfield = Ext.widget('textfield', me.textConfig),
        image = Ext.widget('image', me.imgConfig);

    me.items = [textfield, image];
    me.callParent(arguments); 
},
于 2012-08-02T16:07:13.453 に答える
1

コードを次のように単純化します。

constructor() 関数全体を削除します。あなたはそれを必要としません。

フィールドセットの関数を次のように書き換えinitComponent()ます。

initComponent: function() {
   var me = this;

   Ext.apply(me, items: [{
      xtype: 'textfield',
      value: me.textConfig.value,
      .... 
   }, {
      xtype: 'image',
      src: me.imageConfig.src,
      ... 
   }]);
}
于 2012-08-02T12:33:58.213 に答える