首先了解 Ext.Tree.Node.attributes的用法:
定义如下数据(其中有自定义类型type):
js 代码
- [{"text":"a","id":"1","cls":"folder","type":"4"},{"text":"b","id":"2","cls":"folder","type":"3"}]
通过 Tree.TreeLoader 加载数据后可以通过如下语法读取type自定义属性
js 代码
- node.attributes.type
了解自定义属性用法后可在Tree的contextmenu事件中控制不同类型的结点显示不同的菜单了,关键代码:
js 代码
- prepareCtx:function(node, e){
- node.select();
- if(node.attributes.type=="3");{
- ctxMenu.showAt(e.getXY());
- }
- if(node.attributes.type=="4"){
- ctxMenu1.showAt(e.getXY());
- }
- }
完整例子见附件,注:此例子不中包含ext库文件,如需运行需将ext库文件放入ajax/yui目录