JSVM组件:Destroydrop Dtree For JSVM2
在JSVM框架下,很容易实现组件化。下面这个就是将Destroydrop Dtree 移植到JSVM2下的一个实例。
此前,新建一个 dTree 实例时,需要将 句柄的名称 作为参数传递进去。例如:tree1 = new dTree("tree1"); 其目的是为了回调。这种方式,既缺乏美感也不够灵活。
我在这个版本的移植过程中,稍微改动了一下,取消了这种形式。直接 var tree = new Tree(); 即可。
另外新增了一个 build 方法。代替了原先 document.write(tree) 的方式,直接调用 tree.build() 即可。
另外,如果需要指定tree生成到特定的位置,可以将指定父容器的句柄传递进去即可。例如:
<script>
var tree = new Tree();
//TODO
tree.build(document.getElementById("abc"));
<script>
<div id=abc>
</div>
具体使用实例:http://jsvm.homolo.com/example/uic/dtree/example.html
1
<div class="dtree">
2
3
<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
4
5
<script type="text/javascript">
6
<!--
7
8
// 加载Tree类
9
10
_import("com.destroydrop.dtree.Tree");
11
12
// 创建一个Tree类实例
13
14
var d = new Tree();
15
16
d.add(0,-1,'My example tree');
17
d.add(1,0,'网站','');
18
d.add(2,1,'sina.com','http://news.sina.com.cn');
19
d.add(3,1,'google','http://www.google.com');
20
d.add(4,0,'Node 3','#');
21
d.add(5,3,'Node 1.1.1','#');
22
d.add(6,5,'Node 1.1.1.1','#');
23
d.add(7,0,'Node 4','#');
24
d.add(8,1,'JSVM','http://jsvm.homolo.com#');
25
d.add(9,0,'My Pictures','#','这个是提示!','','');
26
d.add(10,9,'The trip to Iceland','#','Pictures of Gullfoss and Geysir');
27
d.add(11,9,'Mom\'s birthday','#');
28
d.add(12,0,'Recycle Bin','example01.html','','','img/trash.gif');
29
30
d.build();
31
32
//-->
33
</script>
34
35
</div>
<div class="dtree">2

3
<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>4

5
<script type="text/javascript">6
<!--7

8
// 加载Tree类9

10
_import("com.destroydrop.dtree.Tree");11

12
// 创建一个Tree类实例13

14
var d = new Tree();15

16
d.add(0,-1,'My example tree');17
d.add(1,0,'网站','');18
d.add(2,1,'sina.com','http://news.sina.com.cn');19
d.add(3,1,'google','http://www.google.com');20
d.add(4,0,'Node 3','#');21
d.add(5,3,'Node 1.1.1','#');22
d.add(6,5,'Node 1.1.1.1','#');23
d.add(7,0,'Node 4','#');24
d.add(8,1,'JSVM','http://jsvm.homolo.com#');25
d.add(9,0,'My Pictures','#','这个是提示!','','');26
d.add(10,9,'The trip to Iceland','#','Pictures of Gullfoss and Geysir');27
d.add(11,9,'Mom\'s birthday','#');28
d.add(12,0,'Recycle Bin','example01.html','','','img/trash.gif');29

30
d.build();31

32
//-->33
</script>34

35
</div>
浙公网安备 33010602011771号