在我继承的项目上,我需要从使用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);
}
}
}