Hide the last children of an XML data provider (not to be displayed in mx:Tree)
I have an hierachical XML data, and I want to display it as a tree. The XML data is something like this:
<services>
<service name="TestService" endpoint="">
<method name="sayHi">
<parameter name="firstName" />
<parameter name="lastName" />
</method>
<method name="sayGoodbye">
<parameter name="firstName" />
<parameter name="lastName" />
</method>
</service>
<service name="AnotherTestService">
<method name="getName" />
<method name="setName">
<parameter name="name" />
</method>
</service>
</services>
However, I don't want to display the last elements (parameters
) in the tree becaus开发者_开发百科e, well, it is not meant to be displayed, but still it has to be there.
Any advice on how can I achieve that? I am thinking of either extending DefaultDataDescriptor or create a class which implement ITreeDataDescriptor. Which approach will be suitable in this case?
It's very easy, apparently. Just override the isBranch method from DefaultDataDescriptor.
package
{
import mx.controls.treeClasses.DefaultDataDescriptor;
public class ServiceDataDescriptor extends DefaultDataDescriptor
{
public override function isBranch(
node:Object, model:Object = null):Boolean
{
var xmlNode:XML = new XML(node);
if (node.localName() == "method")
return false;
else
return super.isBranch(node, model);
}
}
}
精彩评论