Dojo学习8 使用恐怖的dijit.Tree

8. 使用恐怖的dijit.Tree
可以说dojo0.9bate的dijit.Tree太灵活了,功能太强大了。所以使用的时候定制和编程就要很多了。Dijit.Tree数据源必须是Store,常用的是dojo.data.JsonItemStore ,不能够使用inline方式。
下面给出两个例子,一个例子是最基础的,一个例子是动态生成的:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>TREE</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>
  dojo.require("dojo.data.JsonItemStore");
  dojo.require("dijit.Tree");
    dojo.addOnLoad(function(){
     dojo.subscribe("tree", null, function(message){
      console.log("sn:"+message.event);
      console.log("sn:"+message.node.item.name);
     }); 
    });
 </script>
</head>

<body class="tundra">
<div dojoType="dojo.data.JsonItemStore" jsId="continentStore"
  url="../js/dijit/tests/countries.json"></div>
 <div dojoType="dijit.Tree" id=tree store="continentStore" query="{type:'continent'}"
  labelAttr="name" typeAttr="type"></div>
</body>
</html>

动态添加树节点:
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();
}

如果要懒加载一个树,就需要继承JsonItemStore,可以参考/dojox/data/demos/里面的例子。如果想从其他数据源得到树,可以参考dojox.data里面的其他store.总之,tree的数据源必须是Store。 

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值