javascript - Extjs 将项目添加到扩展类

标签 javascript extjs extjs5

我正在使用 Extjs 5 定义我的自定义工具栏:

Ext.define('Core.toolbar.view.ToolbarView',
{
        extend: 'Ext.toolbar.Toolbar',

        dock: 'top',
        items: [
        {
                xtype: 'button',
                text: 'add'
        },
        {
                xtype: 'button',
                text: 'remove'          
        }]

});

现在我要使用它:

Ext.define('MyApp.view.ToolbarView',
{
        extend: 'Core.toolbar.view.ToolbarView',

        items: [
        {
                xtype: 'button',
                text: 'ADDING AN OTHER BUTTON'
        }]

});

Ext.create('MyApp.view.ToolbarView');

使用 items 属性我用新项目覆盖旧项目,但我不想这样做。我想添加第三个按钮。

可能吗?

最佳答案

我会使用 initComponent,像这样 ( example ):

Ext.application({
  name: 'Fiddle',

  launch: function() {
    Ext.define('Core.toolbar.view.ToolbarView', {
      extend: 'Ext.toolbar.Toolbar',

      dock: 'top',
      items: [{
        xtype: 'button',
        text: 'add'
      }, {
        xtype: 'button',
        text: 'remove'
      }]

    });

    Ext.define('MyApp.view.ToolbarView', {
      extend: 'Core.toolbar.view.ToolbarView',
      initComponent: function() {

        this.callParent();
        this.add({
          xtype: 'button',
          text: 'ADDING AN OTHER BUTTON'
        });
      }

    });

    Ext.create('MyApp.view.ToolbarView', {
      renderTo: Ext.getBody()
    });

    Ext.create('MyApp.view.ToolbarView', {
      renderTo: Ext.getBody()
    });
  }
});

关于javascript - Extjs 将项目添加到扩展类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32315463/

相关文章:

php - 在提交前设置 PHP 值

Extjs 如何在扩展时初始化新元素 - 而不会丢失范围

javascript - ExtJS 5 : Set child View Model data from bound value

javascript - ExtJS 如何在选中和选中时删除网格行下划线

javascript - 当只有一个元素时,字符串数组作为字符串传递到我的 Controller

extjs - Sencha Cmd build - 创建后台进程失败

javascript - AsyncStorage.getItem() 返回一个值和一个 promise

javascript - requiredFieldValidator - 因此,如果禁用 Javascript,则可以避免整个 .NET 控件?

javascript - 仅显示特定国家/地区的链接

javascript - ExtJS 4 - 动态更改折线图中的图例颜色