如何让YUI TreeView右键显示ContextMenu?
YUI的example没有带这个方面的例子。
我首先是自己摸索了一下。失败。
所以还是上了group去看看前人的总结。
有一个例子如下:
Re:[ydn-javascript]Re:AddingContextmenutoTree
chandhrudu,
I'msorry--Imaybemisunderstandingyourquestion.?IpostedtothisthreadaresponsetozmischeabouttheImplementationGallery...IdidnotpostaboutacodesampleforintegratingContextMenuwithTreeView.牋
However,toanswerthelatterquestion...
<script>
(function(){
varinit=function(){
//buildaTreeViewinstancewithonenode:
vartree=newYAHOO.widget.TreeView("treediv");
varroot=tree.getRoot();
varnode1=newYAHOO.widget.TextNode("Labelforfirstnode.",root);
tree.draw();
//gettheelementthatwewanttoattach
//acontextmenuto;inthiscase,we'll
//attachittotheelementencompassing
//thefirst(only)nodeinthetree:
varmyContextEl=node1.getEl();
//createaContextMenuwiththeTreeView's
//nodeasitstrigger:
varoContextMenu=newYAHOO.widget.ContextMenu("mycontextmenu",{trigger:myContextEl});
oContextMenu.addItem("cut");
oContextMenu.addItem("copy");
oContextMenu.addItem("paste");
oContextMenu.render(document.body);
}
YAHOO.util.Event.on(window,'load',init);
})();
</script>
<body>
<divid="treediv"></div>
</body>
</html>
Thiswillcreateaone-nodeTreeViewinstancewhich,whenyouright-clickonthenode,popsupacontextmenu.
Regards,
Eric
chandhrudu,
I'msorry--Imaybemisunderstandingyourquestion.?IpostedtothisthreadaresponsetozmischeabouttheImplementationGallery...IdidnotpostaboutacodesampleforintegratingContextMenuwithTreeView.牋
However,toanswerthelatterquestion...
<script>
(function(){
varinit=function(){
//buildaTreeViewinstancewithonenode:
vartree=newYAHOO.widget.TreeView("treediv");
varroot=tree.getRoot();
varnode1=newYAHOO.widget.TextNode("Labelforfirstnode.",root);
tree.draw();
//gettheelementthatwewanttoattach
//acontextmenuto;inthiscase,we'll
//attachittotheelementencompassing
//thefirst(only)nodeinthetree:
varmyContextEl=node1.getEl();
//createaContextMenuwiththeTreeView's
//nodeasitstrigger:
varoContextMenu=newYAHOO.widget.ContextMenu("mycontextmenu",{trigger:myContextEl});
oContextMenu.addItem("cut");
oContextMenu.addItem("copy");
oContextMenu.addItem("paste");
oContextMenu.render(document.body);
}
YAHOO.util.Event.on(window,'load',init);
})();
</script>
<body>
<divid="treediv"></div>
</body>
</html>
Thiswillcreateaone-nodeTreeViewinstancewhich,whenyouright-clickonthenode,popsupacontextmenu.
Regards,
Eric
本文地址:http://www.45fan.com/a/question/67625.html