如何在Extjs按钮菜单的一个位置编写公共属性

如何在Extjs按钮菜单的一个位置编写公共属性,extjs,Extjs,我有按钮和菜单。菜单上几乎没有什么共同点。如何在公共场所编写此代码,以便优化我的代码。 在我的代码中,两个按钮的图标都相同。类似地,很多事情都会发生,所以如何作为默认值编写 我的代码: Ext.onReady(function() { new Ext.panel.Panel({ renderTo: document.body, title: 'A Panel', width: 200, height: 200, tools: [{ xty

我有按钮和菜单。菜单上几乎没有什么共同点。如何在公共场所编写此代码,以便优化我的代码。 在我的代码中,两个按钮的图标都相同。类似地,很多事情都会发生,所以如何作为默认值编写

我的代码:

Ext.onReady(function() {

new Ext.panel.Panel({
    renderTo: document.body,
    title: 'A Panel',
    width: 200,
    height: 200,
    tools: [{
        xtype: 'button',
        text: 'Foo',
        iconCls:'Item',
        menu: {
            items: [{
                text: 'Item 1',
                iconCls:'Item',
                handler: function() {
                    console.log('Item 1');
                }
            }, {
                text: 'Item 2',
                iconCls:'Item',
                handler: function() {
                    console.log('Item 2');
                }
            }]
        }
    }]
});
});

您可以使用defaults属性

Ext.onReady(function() {

new Ext.panel.Panel({
    renderTo: document.body,
    title: 'A Panel',
    width: 200,
    height: 200,
    tools: [{
        xtype: 'button',
        text: 'Foo',
        iconCls:'Item',
        menu: {
            defaults: {
                iconCls: 'Item'
            },
            items: [{
                text: 'Item 1',
                handler: function() {
                    console.log('Item 1');
                }
            }, {
                text: 'Item 2',
                handler: function() {
                    console.log('Item 2');
                }
            }]
        }
    }]
});
});