ExtJs 给树节点添加右键菜单
很简单,查看ExtJs的API文档,找到TreePanel,然后找到contextmenu ,展开后,会看到如下内容,包括解释和例子!
contextmenu : ( Node node, Ext.EventObject e )
Fires when a node is right clicked. To display a context menu in response to this event, first create a Menu object (…
Fires when a node is right clicked. To display a context menu in response to this event, first create a Menu object (see Ext.menu.Menu for details), then add a handler for this event:
new Ext.tree.TreePanel({
title: ‘My TreePanel’,
root: new Ext.tree.AsyncTreeNode({
text: ‘The Root’,
children: [
{ text: 'Child node 1', leaf: true },
{ text: 'Child node 2', leaf: true }
]
}),
contextMenu: new Ext.menu.Menu({
items: [{
id: 'delete-node',
text: 'Delete Node'
}],
listeners: {
itemclick: function(item) {
switch (item.id) {
case ‘delete-node’:
var n = item.parentMenu.contextNode;
if (n.parentNode) {
n.remove();
}
break;
}
}
}
}),
listeners: {
contextmenu: function(node, e) {
// Register the context node with the menu so that a Menu Item’s handler function can access
// it via its parentMenu property.
node.select();
var c = node.getOwnerTree().contextMenu;
c.contextNode = node;
c.showAt(e.getXY());
}
}
});
Listeners will be called with the following arguments:
* node : Node
The node
* e : Ext.EventObject
The event object
文档中对于 配置项中并没有出现 contextmenu ,但是例子中却可以直接配置。由此也看出,并不是所有的配置项都在API中列出了。
近期评论