在我繼承的項目上,我需要從使用Spark List組件切換到使用mx Tree組件,以便能夠將項目分組到目錄中。我對Flex/XML非常生疏,所以我想知道如果我能夠正確地指導如何處理這個問題。爲Flex樹組件解析XML
我的問題(詳細信息/數據如下細節):
我如何檢測 'studentGroup' 節點從 '學生' 的節點?
樹組件需要一個字段用於顯示名稱。我的 必須在'studentGroup'節點和'學生' 節點之間有一個共同名稱嗎?
我完全做錯了嗎?
以前我的XML數據持平(我已經剝離出來爲清晰起見所有的細節):
<studentList>
<student>
<studentName>Sam</studentName>
</student>
<student>
<studentName>Ruby</studentName>
</student>
</studentList>
新格式組和學生個人的混合體:
<studentList>
<studentGroup>
<studentGroupName>Chess</studentGroupName>
<student>
<studentName>Betty</studentName>
</student>
</studentGroup>
<student>
<studentName>Sam</studentName>
</student>
<student>
<studentName>Ruby</studentName>
</student>
</studentList>
XML目前正在使用此(再次簡化)代碼進行分析:
for each (var prop:XML in studentsXML.file){
tempArray = new ArrayCollection();
for each(var studentProp:XML in prop.studentList.student){
tempStudent = new Student(studentProp.studentName);
tempArray.addItem(tempStudent);
}
}
我需要改變它,以便'studentGroups'我做一件事,'學生'我像上面那樣處理它。在僞代碼中,它看起來像下面的內容,但是我正在語法上跳動(或者我完全偏離了軌道?)。
for each (var prop:XML in studentsXML.file){
tempArray = new ArrayCollection();
for each(var studentProp:XML in prop.studentList){
//HOW DO I DETECT A StudentGroup FROM A Student NODE?
if (studentList.studentGroup){
//student group
tempStudentGroup = new StudentGroup(studentProp.studentGroupName);
for each(var student:XML in studentList.studentGroup){
tempStudent = new Student(studentProp.studentName);
tempStudentGroup.add(tempStudent);
}
tempArray.addItem(tempStudentGroup);
}else{
//single student
tempStudent = new Student(studentProp.studentName);
tempArray.addItem(tempStudent);
}
}
}