문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top