Frage

In Ext JS 4.1.1, how do I programmatically add items to a buttongroup? If I add items as part of defining a buttongroup, it works, for eg:

Ext.define('company.ButtonGroup', {
    extend: 'Ext.container.ButtonGroup',
    title: 'File',
    columns: 2,
    defaults: {
        scale: 'small'
    },
    items: [
            { text: 'New', iconCls: 'new16' },
            { text: 'Open', iconCls: 'open16' }
            ]
});
var fileButtongroup = Ext.create('company.ButtonGroup');

However, if I try to assign an array of items, it doesn't work. For eg:

var fileArr = [
            { text: 'New', iconCls: 'new16' },
            { text: 'Open', iconCls: 'open16' }
            ];
Ext.define('company.ButtonGroup', {
    extend: 'Ext.container.ButtonGroup',
    title: 'File',
    columns: 2,
    defaults: {
        scale: 'small'
    }
});
var fileButtongroup = Ext.create('company.ButtonGroup');
fileButtongroup.items = fileArr;

Further, I don't see any setItems() method also.

War es hilfreich?

Lösung

Because the items array gets processed upon component initialization (in initComponent()).

If you want to add items to your button group after you create it, you should use the add() method. By the way it works on any Container class.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top