【发布时间】:2011-03-29 22:39:47
【问题描述】:
我有以下 xml:
<objects>
<property name="steps">
<property name="array">
<object type="com.tn.assistant.models.Step">
<property name="preDialogues">
<property name="array">
<object type="com.tn.assistant.models.Dialogue"/>
</property>
</property>
<property name="question">
<object type="com.tn.assistant.models.Question">
</object>
</property>
</object>
</property>
</property>
</objects>
我在 Flex 4 / air 应用程序中用树显示它。我需要过滤掉“步骤”、任何“数组”节点和“preDialogues”。他们不应该出现在树上,但他们的孩子应该出现。我扩展了 DefaultDataDescriptor,并覆盖了 getChildren(),以成功过滤步骤和数组标签。
override public function getChildren(node:Object, model:Object=null):ICollectionView
{
var ch:XMLList = new XMLList (node.xns::*);
var retXMLList:XMLList = new XMLList();
var retXMLListCtr = 0;
for (var i = 0; i < ch.length(); i++){
if (ch[i].@name == "array"){
return getChildren(ch[i]);
}
else if (ch[i].@name == "steps"){
return getChildren(ch[i]);
}
/*
else if (ch[i].@name == "preDialogues"){
return getChildren(ch[i]);
}
*/
else {
retXMLList[retXMLListCtr] = ch[i];
retXMLListCtr++;
}
}
var chil:XMLListCollection = new XMLListCollection (retXMLList);
var chil2:ICollectionView = ICollectionView(chil);
return chil2;
}
此代码成功过滤掉“步骤”和“数组”。但是,如果我取消注释“preDialogues”代码以尝试过滤掉 preDialogues,问题节点将被完全跳过。我知道为什么会发生这种情况,但我能做些什么呢?自从我完成递归以来已经有一段时间了。我以为我可以返回某种组合列表或其他东西,但我什么也做不了。谢谢。
【问题讨论】:
标签: apache-flex recursion tree