Is there any way to prevent displaying the ">" caret before the tree node if the node has no children? I'd like it to not display when children is an empty ArrayCollection. I know you can set the arraycollection to null but I'd prefer to avoid then having to do all the null checks throughout the code.
create a custom renderer like this:
package com.simmone.renderers {
import mx.collections.*;
import mx.controls.treeClasses.*;
import mx.controls.listClasses.ListBase;
public class MyTreeItemRenderer extends TreeItemRenderer {
public function MyTreeItemRenderer() {
super();
}
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if( data.children.length == 0 ) {
super.disclosureIcon.visible = false;
}
}
}
}
mxml:
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var dataArray:Array = [
{label:"father1", children:
[{label:"child1"},
{label:"child2"}]},
{label:"father2", children:[]}];
[Bindable]
private var dataList:ArrayCollection = new ArrayCollection(dataArray);
]]>
</fx:Script>
<mx:Tree id="tr1" width="100%" height="80"
dataProvider="{dataList}"
labelField="label"
borderVisible="false"
itemRenderer="com.simmone.renderers.MyTreeItemRenderer"/>
and I find that if use xmllist, haven't this problem, if no children, will not display discloure icon.