我有兩個xml文件,缺陷。 xml和employee.xml。但文件有一個共同的字段,但在每個文件中有不同的名稱。我希望將這兩個文件合併到一個數組集合中。如何在flex中的單個數組集合中獲取兩個xml文件?
我defect.xml文件的結構是:
<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>
而且我employee.xml
<Employees>
<employee>
<employeeId>256148</employeeId>
<employeeName>Angeline</employeeName>
</employee>
<employee>
<employeeId>256158</employeeId>
<employeeName>Aarthi</employeeName>
</employee>
<Employees>
我得到兩個XML文件有兩種陣列集合:
<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}"/>
當「assignedTo」匹配「employeeName」時,我希望「employeeId」被添加到defectList數組集合中。我怎樣才能做到這一點? 如何遍歷數組集合?
如何檢查defectList中的assignedTo字段是否等於employeeList中的employeeName字段?有人指導我..
編輯
好了,現在我可以比較這兩個領域,defectList和employeeList.Thanks的employeeName的assignedTo西蒙:
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 .
}
}
}
但如何將employeeId字段添加到特定的數組元素,以便我可以使用defectList作爲datagrid的顯示員工ID的數據提供者?有人可以幫我弄這個嗎。
SOLUTION
我已經找到了解決辦法。下面是代碼:
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;
}
}
}
}
現在,如果我給數據字段作爲與defectList數據網格作爲dataProvider,「僱員」,我得到了相應的僱員姓名的員工ID。
好的,我可以比較這些元素。那就是。但是如何將字段「EmployeeId」添加到defectList數組集合中?任何想法? – Angeline 2009-10-27 13:36:16
非常感謝您的幫助。我找到了解決方案:-) – Angeline 2009-10-27 14:11:47