extjs4 tree如果获取节点属性
http://blog.csdn.net/leecho571/article/details/6799059
?
Ext4改了好多,树控件都改得自己不认识了,切入正题:
在Ext3中只要注册了'click','contextmenu',就会将Node对象传进来,代码示例:
?
[javascript] view plaincopyprint?
- contextmenu?:?function(Ext.tree.TreeNode,Ext.EventObject?e)??
这样到话就可以直接得到node对象,但在Ext4中变化好大了,传进来的没有Node对象,代码示例:
?
?
[javascript] view plaincopyprint?
- itemcontextmenu(?Ext.view.View?this,?Ext.data.Model?record,?HTMLElement?item,?Number?index,?Ext.EventObject?e)??
传进来到参数得不到Node对象就无法操纵树,今天看了源码,看了文档终于研究了好久才得出了一个结论:
其实record里面就包含了Ext3中treeNode到方法,recorrd就是Node对象。区别在于,Ext4中record只是完全跟数据相关,不跟页面展示发生关系,页面展示通过Ext.tree.View实现。
下面所一段Ext.tree.View中的源码:
?
[javascript] view plaincopyprint?
- setNode:?function(node)?{??
-
????????var?me?=?this;??
- ??????????
-
????????if?(me.node?&&?me.node?!=?node)?{??
- ??????????????
- ????????????me.mun(me.node,?{??
- ????????????????expand:?me.onNodeExpand,??
- ????????????????collapse:?me.onNodeCollapse,??
- ????????????????append:?me.onNodeAppend,??
- ????????????????insert:?me.onNodeInsert,??
- ????????????????remove:?me.onNodeRemove,??
- ????????????????sort:?me.onNodeSort,??
- ????????????????scope:?me??
- ????????????});??
-
????????????me.node?=?null;??
- ????????}??
- ??????????
-
????????if?(node)?{??
-
????????????<span?style="color:#FF0000;">Ext.data.NodeInterface.decorate(node);</span>??
- ????????????me.removeAll();??
-
????????????if?(me.rootVisible)?{??
- ????????????????me.add(node);??
- ????????????}??
- ????????????me.mon(node,?{??
- ????????????????expand:?me.onNodeExpand,??
- ????????????????collapse:?me.onNodeCollapse,??
- ????????????????append:?me.onNodeAppend,??
- ????????????????insert:?me.onNodeInsert,??
- ????????????????remove:?me.onNodeRemove,??
- ????????????????sort:?me.onNodeSort,??
- ??????