首先了解 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目录
ExtJS Tree 自定义节点
本文介绍如何在ExtJS框架中使用Tree组件的自定义属性type,并通过Tree.TreeLoader加载数据后,根据type属性的不同值在上下文菜单中展示不同选项。
728

被折叠的 条评论
为什么被折叠?



