1. dijit.Tree 中的节点属性除固有属性外,还可以随意添加
{identifier: 'id',label: 'name',items: [{ id: '0', name:'李英夫', department : 'w3', children:[ {_reference: '1'}, {_reference: '2'}, {_reference: '3'} ] },{ id: '1', name:'Fruits',children:[ {_reference: '4'} ] },{ id: '4',name:'Citrus', children:[ {_reference: '5'} ] },{ id: '5', name:'Orange'},{ id: '2', name:'Vegetables'},{ id: '3',name:'Cereals'}]}
其中department : 'w3'就是后添加的
2. 节点移动后触发的方法是dijit.tree.dndSource中的onDndDrop方法.这个后备.这个方法不能随便改,改了容易出问题.
3. dijit.Tree中的OnClick方法是单击节点时触发的方法,可以对应其它方法, 如OnClick : testclick
function testclick(item){
//这里的item就是对应json中item属性的
//lastSelected=item;//这是记录最后点击的节点,为了添加节点而设置
alert("工号:" + item.id + "\n姓名:" + item.name + "\n部门:"+item.department);
}
<div data-dojo-id="catModel" data-dojo-type="dijit.tree.TreeStoreModel" data-dojo-props='store:myStore, query:{id: "0"}'></div>
<div id="collectionsTree" data-dojo-type="dijit.Tree" data-dojo-props='"class":"container", model:catModel,
betweenThreshold:5,
getIconClass:getIcon, //这个是可以改变节点样式的方法
onClick:testclick, //这个就是单击事件
persist:false'></div>
还有这样的写法
<div class="container" dojoType="dijit.Tree" id="itemTree"
model="itemModel"
dndController="dijit.tree.dndSource"
checkAcceptance="dndAccept"
checkItemAcceptance="itemTreeCheckItemAcceptance"
dragThreshold="8"
getIconClass="getIcon"
persist="false"></div>