Arrays 使用关联数组更新数组节点

Arrays 使用关联数组更新数组节点,arrays,xml,actionscript-3,apache-flex,flex4.5,Arrays,Xml,Actionscript 3,Apache Flex,Flex4.5,我有一个数组,如: > ObjectArr[ID,x,y,distance,Type]; 还有一个xml,如: objectXML = <objects> <object id={ID} x={x} y={y} distance={distance}>{Type}</object> <object id={ID} x={x} y={y} distance={distance}>{Type}</obj

我有一个数组,如:

> ObjectArr[ID,x,y,distance,Type];
还有一个xml,如:

 objectXML = 
    <objects>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
    </objects>
我是这样做的:

for(var i:int = 0; i < objectXML.length(); i++)
{
  objectXML.object[i].@ID = objectArr[i].ID;
  objectXML.object[i].@x = objectArr[i].x;
  objectXML.object[i].@y = objectArr[i].y;
  objectXML.object[i].@distance = objectArr[i].distance;
  objectXML.object[i]= objectArr[i].Type;
}
for(var i:int=0;i
但是xml没有按照数组元素进行更新。 我应该选择其他解决方案吗

如果我需要在删除后更新xml,我应该怎么做?? 为了删除数组,我写了这么多

var ID:String = Obj.getObjectId();
for(var i:int=0; i < objectArr.length; i++)
{
  if(objectArr[i].objID == ID)
  objectArr.splice(i, 1);
}
var-ID:String=Obj.getObjectId();
for(变量i:int=0;i
为了删除xml节点,我编写了以下代码:

for(var i:int = 0; i<objectXML.object.length();i++)
{
  if(objectXML.object.length() && objectXML.object[i].@objID == objectArr[i].objID)
     delete objectXML.object[i];
}
for(变量i:int=0;i
  • length()等于1,而不是4
  • @ID应为小写,以匹配xml中的ID属性
试试这个:

for(var i:int = 0; i < objectXML.object.length(); i++){
   objectXML.object[i].@id=objectArr[i].ID;
   //....
}
for(var i:int=0;i
谢谢你……这只是一个愚蠢的错误,但花费了我很多时间……我只是忘了检查长度……很高兴知道这有帮助:)我已经编辑了问题,因此我取消选择了已接受的分数……所以在我得到答案后,我会选择你的答案作为正确答案。
for(var i:int = 0; i < objectXML.object.length(); i++){
   objectXML.object[i].@id=objectArr[i].ID;
   //....
}