jQuery.treeview 树界降临

农民工的小康生活都是浮云,明天终于要加班了。。。
放下杯具,开始调戏代码吧。

  最近搞了半天(办了很多天)的树,让哥哥我被玩够了。终于忍不住重整了一遍,将每个树节点构造成 TreeNode 的一个实例,存放在 dx_tree 数组中。TreeNode 有显示图层信息和加载子节点的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
window.dx_tree=[];

function TreeNode(id, name, isDir, initLayer) {
    function _treenode(){
        this.id = id;
        this.name = name;
        this.isDir = isDir;
        this.initLayer = initLayer;
    }
    this.prototype.createMe = function() {
        //创建国人这个节点
        window.dx_tree[id] = this;
    };
    this.prototype.createChildren = function() {
        //创建国人娃儿这些节点(利用createMe)
    }
}

有了 TreeNode 类在写右键功能的时候都方便多了。现在直接将 initLayer() 方法传入 TreeNode 中(是不是叫闭包哦?),在每次创建 TreeNode 实例的时候都会复制一遍 initLayer() 方法,有点犯罪感。。。不知怎么解决?