How to create custom ExtJS form field component?

后端 未结 9 543
无人共我
无人共我 2020-12-02 11:34

I want to create custom ExtJS form field components using other ExtJS components in it (e.g. TreePanel). How can I do it most easily?

I\'ve read doc

9条回答
  •  -上瘾入骨i
    2020-12-02 11:59

    Following the documentation at http://docs.sencha.com/ext-js/4-0/#/api/Ext.form.field.Base

    This code will create a reusable TypeAhead/Autocomplete style field for selecting a language.

    var langs = Ext.create( 'Ext.data.store', {
        fields: [ 'label', 'code' ],
        data: [
            { code: 'eng', label: 'English' },
            { code: 'ger', label: 'German' },
            { code: 'chi', label: 'Chinese' },
            { code: 'ukr', label: 'Ukranian' },
            { code: 'rus', label: 'Russian' }
        ]
    } );
    
    Ext.define( 'Ext.form.LangSelector', {
        extend: 'Ext.form.field.ComboBox',
        alias: 'widget.LangSelector',
        allowBlank: false,
        hideTrigger: true,
        width: 225,
        displayField: 'label',
        valueField: 'code',
        forceSelection: true,
        minChars: 1,
        store: langs
    } );
    

    You can use the field in a form simply by setting the xtype to the widget name:

    {
        xtype: 'LangSelector'
        fieldLabel: 'Language',
        name: 'lang'
    }
    

提交回复
热议问题