ExtJS arrowHandler需要引用它所属的splitbutton

时间:2017-01-13 21:48:38

标签: javascript extjs

在下面的代码中,Ext.getCmp不起作用,因为它们在被调用时并未完全定义。我怎么能抓住这两件事呢?

此外,还有另一部分代码不断推送到list.menu.buttons,这就是为什么只有在点击箭头时我才需要将它们添加到项目中。

xtype: "splitbutton",
id: "list",
enableToggle: true,
arrowHandler: (function () {
                var library = Ext.getCmp("library");
                var buttons = Ext.getCmp("list").menu.buttons;
            function btn(num) {
                var image = new Image;
                image.src = buttons[num].dataURL;
                this.xtype = "button";
                this.height = 50;
                this.width = 50;
                this.icon = image;
                this.num = num;
                this.handler = function (btn) {
                    btn.up("button").fireEvent("selected", this.num);
                };
            }
            for (var i = 1; i <= 1; i++)
                library.push(new btn(i));
        })(),
menu: {
    plain: true,
    buttons: [],                            
    items: [
        {
            xtype: "ribbon_gallery",
            columns: 3,
            title: "Recent",
            id: "recent",
            items: []
        },
        {
            xtype: "ribbon_gallery",
            columns: 3,
            title: "Library",
            id: "library",
            itemId: "library",
            items: []
        }
    ]
}

1 个答案:

答案 0 :(得分:1)

问题是您已为 arrowHandler 配置指定了self-invoked功能

  arrowHandler: (function() {...})()

您需要“正常”功能

  arrowHandler: function() {...}