I have two xml files, defect. xml and employee.xml. But the files havea common field but with different names in each file. I want both the files to be merged in to a single array collection.
The structure of my defect.xml file is:
<defectList>
<defect>
<revId>123</revId>
<revType>IQA</revType>
<status>Review Pending</status>
<assignedTo>Angeline</assignedTo>
<loggedBy>chandran</loggedBy>
<closedDate>13-10-2009</closedDate>
</defect>
<defect>
<revId>124</revId>
<revType>IQA</revType>
<status>Review Pending</status>
<assignedTo>Aarthi</assignedTo>
<loggedBy>chandran</loggedBy>
<closedDate>15-10-2009</closedDate>
</defect>
<defectList>
And my employee.xml
<Employees>
<employee>
<employeeId>256148</employeeId>
<employeeName>Angeline</employeeName>
</employee>
<employee>
<employeeId>256158</employeeId>
<employeeName>Aarthi</employeeName>
</employee>
<Employees>
I get both the xml files in two array collections:
<mx:Model id="employeeXML" source="assets/employee.xml"/>
<mx:ArrayCollection id="employeeList" source="{employeeXML.employee}"/>
<mx:Model id="defectXML" source="assets/defect.xml"/>
<mx:ArrayCollection id="defectList" source="{defectXML.defect}"/>
when "assignedTo" matches "employeeName", I want the "employeeId" to be added to the defectList array collection. How can I do this? How to iteerate through an array collection?
And how to check if the assignedTo field in defectList equals employeeName field in employeeList? Some one guide me..
EDIT
ok, Now I'm able to compare the two fields,assignedTo of defectList and employeeName of employeeList.Thanks to Simon:
var defect:Object;
var employee:Object;
for each (defect in defectList)
{
for each (employee in employeeList)
{
if(defect.assignedTo == employee.employeeName)
{
// defectList.addItem(employee.employeeId);
// I tried this,but it is wrong .
}
}
}
But how to add the employeeId field to that particular array element,so that I could use defectList as the dataprovider for the datagrid n display employee Id also? Can someone help me with this.
SOLUTION
I have found out the solution. Here is the code:
public function init():void{
var defect:Object;
var employee:Object;
for each (defect in defectList)
{
for each (employee in employeeList)
{
if(defect.assignedTo == employee.employeeName)
{
var id:Object;
id=employee.employeeId;
defect["employeeId"]=id;
}
}
}
}
Now, if I give datafield as "employeeId" in the datagrid with defectList as dataprovider, I get the employee id of the corresponding Employee Name.