欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ext JS 4.0 Tree实战(完美解决TreeNode动态刷新问题) 博客分类: ExtJS4 EXTjsonJavaScript 

程序员文章站 2024-02-04 15:30:16
...
由于个人时间问题,且鉴于上次Grid实战发布经验,完整代码我就不放了,只发布有价值的代码片段。节省大家时间。

本文只描述技术要点:
1,上JSON
[{"pkid":177,"text":"1","mkljdz":"1","bj":1,"xh":1,"fjmk":"3","cjxgrq":"May 17, 2011 7:47:50 PM","zmks":0,"lb":"0","jz":"1","leaf":true},{"pkid":178,"text":"2","mkljdz":"2","bj":1,"xh":2,"fjmk":"3","cjxgrq":"May 17, 2011 7:48:07 PM","zmks":0,"lb":"0","jz":"2","leaf":true},{"pkid":179,"text":"3","mkljdz":"3","bj":1,"xh":3,"fjmk":"3","cjxgrq":"May 17, 2011 7:48:38 PM","zmks":0,"lb":"0","jz":"3","leaf":true},{"pkid":180,"text":"4","mkljdz":"4","bj":1,"xh":4,"fjmk":"3","cjxgrq":"May 17, 2011 7:49:37 PM","zmks":0,"lb":"0","jz":"4","leaf":true},{"pkid":181,"text":"5","mkljdz":"5","bj":1,"xh":5,"fjmk":"3","cjxgrq":"May 17, 2011 7:51:20 PM","zmks":0,"lb":"0","jz":"5","leaf":true}]

必要字段:pkid text fjmk leaf
说明:Tree的JSON是数组格式的,pkid的值是节点的id、text的值是节点的名字、fjmk的值为父级模块的pkid、leaf表示是否为leaf节点。

2,技术要点
很多朋友不知道4的树节点视图如何动态更新,上核心代码段
listeners : {
itemclick : function(view, rec, node) {//树节点单击时候记录下view、record、node
View = view;
Rec = rec;
Node = node;
view.expand(rec);//单击展开子节点
}

//这段代码很关键,与ExtJS3刷新node的方法完全不一样
Rec.removeAll();//清空当前节点下的子节点
xtmkTreeStore.load({
node : Rec,//读取当前节点
callback : function() {
View.refresh();//刷新树视图!
}
});


最后,goodluck everyone!