Dojo学习13 dijit.Tree 动态添加节点之一

13. dijit.Tree 动态添加节点之一
对dijit.Tree研究了很久,源代码也看了好多遍了。对于fx这个类的研究还需要更深入一步。动态添加树的节点已经完成了。
与大家分享一下:
===========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test tree , dynamic add treenode</title>
<style type="text/css">
 @import "../js/dojo/resources/dojo.css";
 @import "../js/dijit/themes/tundra/tundra.css";
</style> 
<script type="text/javascript"
 djConfig="parseOnLoad: true, isDebug: true"
 src="../js/dojo/dojo.js"></script>
<script type="text/javascript">
/*
 author : amushen
 date:20070716
 email:amushen@gmail.com
*/
 dojo.require("dijit.form.Button");
 dojo.require("dijit.Tree");
 dojo.require("dojo.data.JsonItemStore");
function init(){
 var treeData={identifier: 'name',
      label: 'name',
      items: [
     { name:'China', type:'one',children:[{reference:'beijing'}] },
         { name:'beijing', type:'city'},
     { name:'USA' , type:'one'},
     { name:'UK' , type:'one'}
    ]
 };
 var store1=new dojo.data.JsonItemStore({data:treeData});
 
 var _tree=new dijit.Tree({
  widgetId:"tree",
  store:store1,
  query:{type:'one'},
  labelAttr:"name",
  typeAttr:"type"},dojo.byId("tree"));
}
dojo.addOnLoad(init);
function addNode(){
 //add one treeNode
 var _tree=dijit.byId("tree");
 var tdata={label:"FR",tree:_tree,item:{name:"FR",type:"one"}};
 var child=new dijit._TreeNode(tdata);  
 _tree.addChild(child,1);
 child._updateLayout();
 _tree.getChildren()[2]._updateLayout();
 child.setChildren({});
 child._setExpando();
// console.debug();
}
function addSecondNode(){
 // add a treenode for FR
 var _tree=dijit.byId("tree");
 var fr=_tree.getChildren()[1];
 var tdata=[{label:"Paris",item:{type:"city",name:"Paris"}}];
 fr.setChildren(tdata);
 fr.getChildren()[0].setChildren({});
 fr.isFolder=true;
 fr.isExpanded=false;
 fr._updateLayout();
 fr._setExpando();
}
function addThirdNode(){
 var _tree=dijit.byId("tree");
 var fr=_tree.getChildren()[1];
 var tdata={label:"pp",tree:_tree,item:{name:"pp",type:"city"}};
 var child=new dijit._TreeNode(tdata);  
 child.setChildren({});
 fr.addChild(child);
 child._updateLayout();
 fr.getChildren()[0]._updateLayout();
}
</script>
</head>
<body class="tundra">
<button id="b1" dojoType="dijit.form.Button" οnclick="addNode()">add a treeNode</button>
<button id="b2" dojoType="dijit.form.Button" οnclick="addSecondNode()">add another treeNode</button>
<button id="b3" dojoType="dijit.form.Button" οnclick="addThirdNode()">add third treeNode</button>
<div id=tree></div>
</body>
</html>

转载于:https://my.oschina.net/ykai/blog/9468

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值