flex中 怎么控制 tree 中节点的拖拽
就是一个tree怎么设置哪个节点不可以被拖拽哪个节点不可以让别的节点放进来..求flex高手...补充:(根节点下面只有一个节点,就是得保证根节点下面不可以再增加别的节点...
就是一个 tree 怎么设置 哪个节点不可以 被拖拽 哪个节点不可以让别的 节点放进来..求flex 高手...补充:(根节点下面只有一个节点,就是得保证根节点下面不可以再增加别的节点,并且我的现在可以把别的节点拖动到根节点的位置。。)tree 已经设置好了 可以拖动的
展开
1个回答
2013-08-03
展开全部
代码:dragDrop="drag(event)"
dragStart = "setselecteds(event)"private function drag(event:DragEvent):void{
if(organizationTree.selectedItem==null)return;
var currNodeOver:TreeItemRenderer= TreeItemRenderer(event.currentTarget.indexToItemRenderer(event.currentTarget.calculateDropIndex(event)));
if(currNodeOver==null)return;
var orgxml:XML = organizationTree.selectedItem as XML;
var orgId:String = orgxml.@id;
var parentOrgId:String = currNodeOver.data.@id;
var oldParentxml:XML = orgxml.parent() as XML;
var xml:XML = organizationTree.selectedItem as XML;
var currXml:XML = currNodeOver.data as XML;
var parentxml:XML=currXml.parent() as XML;
var gparentxml:XML=currXml as XML;
while(gparentxml.@id !=null)
{
if(xml==gparentxml)return
gparentxml=gparentxml.parent() as XML;
}
var orgVO:OrganizationVO = new OrganizationVO();
orgVO.id = orgId;
orgVO.displayName = organizationTree.selectedItem.@displayName;
orgVO.parentOrgId = parentOrgId; if(currXml.@displayName=="组织结构"||currXml.@id=="null"||currXml.@id==""||currXml.@id==null||orgVO.displayName=="组织结构"){
//Alert.show("不能这么移动");
return;
}
Alert.show("是否把-"+organizationTree.selectedItem.@displayName+"-移动到-"+currXml.@displayName+"-组织下面", "请确认是否为自己的操作", 3, this, function alertClickHandler(event:CloseEvent):void {
if (event.detail==Alert.NO){
if(parentxml.@id == oldParentxml.@id){
//Alert.show("他们属于同一个级别下面的,不要求做别的处理","提示");
return;
}else{
for(var i:uint;i<parentxml.child("node").length();i++){
if(parentxml.child("node")[i].@id==xml.@id){
//Alert.show("移动回来","提示");
delete parentxml.children()[i];
oldParentxml.appendChild(xml);
}
}
return;
}
}
else{
organization.modifyParentOrgId(orgVO,function dragResult(result:Object):void{
for(var i:uint;i<parentxml.child("node").length();i++){
if(parentxml.child("node")[i].@id==xml.@id){
delete parentxml.children()[i]; //删除自己
}
}
// 加载新数据
currXml.@isLoad = false;
oldParentxml.@isLoad = false;
for(var oai:int=0;oai<organization_arr.length;oai++){
if(organization_arr[oai].id==orgId){
organization_arr[oai].parentOrgId = parentOrgId;
break;
}
}
for(var orgIndex:int=0;orgIndex<UserMessage.organization_all.length;orgIndex++){
if(UserMessage.organization_all[orgIndex].id == orgId){
UserMessage.organization_all[orgIndex].parentOrgId = parentOrgId;
break;
}
}
onlyLoadTree = true;
organizationTree.selectedItem = oldParentxml;
treeChanged();
organizationTree.selectedItem = currXml;
treeChanged();
organizationTree.selectedItem = orgxml
onlyLoadTree = false;
});
}
});
}
dragStart = "setselecteds(event)"private function drag(event:DragEvent):void{
if(organizationTree.selectedItem==null)return;
var currNodeOver:TreeItemRenderer= TreeItemRenderer(event.currentTarget.indexToItemRenderer(event.currentTarget.calculateDropIndex(event)));
if(currNodeOver==null)return;
var orgxml:XML = organizationTree.selectedItem as XML;
var orgId:String = orgxml.@id;
var parentOrgId:String = currNodeOver.data.@id;
var oldParentxml:XML = orgxml.parent() as XML;
var xml:XML = organizationTree.selectedItem as XML;
var currXml:XML = currNodeOver.data as XML;
var parentxml:XML=currXml.parent() as XML;
var gparentxml:XML=currXml as XML;
while(gparentxml.@id !=null)
{
if(xml==gparentxml)return
gparentxml=gparentxml.parent() as XML;
}
var orgVO:OrganizationVO = new OrganizationVO();
orgVO.id = orgId;
orgVO.displayName = organizationTree.selectedItem.@displayName;
orgVO.parentOrgId = parentOrgId; if(currXml.@displayName=="组织结构"||currXml.@id=="null"||currXml.@id==""||currXml.@id==null||orgVO.displayName=="组织结构"){
//Alert.show("不能这么移动");
return;
}
Alert.show("是否把-"+organizationTree.selectedItem.@displayName+"-移动到-"+currXml.@displayName+"-组织下面", "请确认是否为自己的操作", 3, this, function alertClickHandler(event:CloseEvent):void {
if (event.detail==Alert.NO){
if(parentxml.@id == oldParentxml.@id){
//Alert.show("他们属于同一个级别下面的,不要求做别的处理","提示");
return;
}else{
for(var i:uint;i<parentxml.child("node").length();i++){
if(parentxml.child("node")[i].@id==xml.@id){
//Alert.show("移动回来","提示");
delete parentxml.children()[i];
oldParentxml.appendChild(xml);
}
}
return;
}
}
else{
organization.modifyParentOrgId(orgVO,function dragResult(result:Object):void{
for(var i:uint;i<parentxml.child("node").length();i++){
if(parentxml.child("node")[i].@id==xml.@id){
delete parentxml.children()[i]; //删除自己
}
}
// 加载新数据
currXml.@isLoad = false;
oldParentxml.@isLoad = false;
for(var oai:int=0;oai<organization_arr.length;oai++){
if(organization_arr[oai].id==orgId){
organization_arr[oai].parentOrgId = parentOrgId;
break;
}
}
for(var orgIndex:int=0;orgIndex<UserMessage.organization_all.length;orgIndex++){
if(UserMessage.organization_all[orgIndex].id == orgId){
UserMessage.organization_all[orgIndex].parentOrgId = parentOrgId;
break;
}
}
onlyLoadTree = true;
organizationTree.selectedItem = oldParentxml;
treeChanged();
organizationTree.selectedItem = currXml;
treeChanged();
organizationTree.selectedItem = orgxml
onlyLoadTree = false;
});
}
});
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询