Javascript ExtJS arrowHandler需要引用它所属的splitbutton
在下面的代码中,Ext.getCmp不起作用,因为它们在被调用时没有完全定义。我怎样才能抓住这两样东西 另外,还有另一部分代码不断地按list.menu.buttons,所以我需要在单击箭头时才将它们添加到项目中Javascript ExtJS arrowHandler需要引用它所属的splitbutton,javascript,extjs,Javascript,Extjs,在下面的代码中,Ext.getCmp不起作用,因为它们在被调用时没有完全定义。我怎样才能抓住这两样东西 另外,还有另一部分代码不断地按list.menu.buttons,所以我需要在单击箭头时才将它们添加到项目中 xtype: "splitbutton", id: "list", enableToggle: true, arrowHandler: (function () { var library = Ext.getCmp("library");
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: []
}
]
}
问题是您已经为arrowHandler配置指定了一个函数 你需要一个正常的函数
arrowHandler: (function() {...})()
arrowHandler: function() {...}