用delete删除XML和XMLListCollection的节点

来源:互联网 发布:mysql 时间序列 编辑:程序博客网 时间:2024/06/05 11:33

Problem Summary

simply using the Delete key work in Flex does not work most of the time and if you have a Tree that's bound to the XMLListCollection Flex will mess up the Tree Selection after deleting an XML element.

Solution Summary

Use a custom method to for loop and delete proper child and reset tree selection

Explanation

 

Use this method:

   private function xmlDeleteNode(xmlToDelete:XML):Boolean
    {
     var cn:XMLList = XMLList(xmlToDelete.parent()).children();
     
     for ( var i:Number = 0 ; i < cn.length() ; i++ )
     {
      if ( cn[i] == xmlToDelete )
      {
      delete cn[i];     
       return true;
      }
     }    
    
     return false;
    
    }

 

Also, remember to do on an XML Bound Tree Control:

myTree.selectedItem = null;

注:XMLList 不支持 delete