flex4 mx |树 - 项目顺序改变,当我折叠和展开一个项目 [英] flex4 mx|Tree - items order change when i fold and unfold an item
问题描述
任何想法?
我的Main.mxml文件:
<?xml version =1.0encoding =utf-8?>
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mxminWidth =955minHeight =600>
<! - 通过在这个类中右键单击启动你的应用程序并选择Debug As> FDT SWF应用程序 - >
< fx:声明>
< fx:XML id =moshe>
<通知>
< root label =astate =root_item>
< node state =itemlabel =moshe/>
< node state =itemlabel =moshe/>
< / root>
< root label =bstate =root_item/>
< root label =cstate =root_item/>
< root label =dstate =root_item/>
< root label =estate =root_item/>
< / notifications>
< / fx:XML>
< / fx:声明>
folderOpenIcon ={null}/>
< / s:Application>
和我的物品渲染器:
<?xml version =1.0encoding =utf-8?>
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mx>
< s:州>
< s:State name =root_item/>
< / s:州>
< fx:Script>
<![CDATA [
import com.flexer.Debug;
导入mx.controls.Alert;
覆盖公共函数集数据(value:Object):void {
super.data = value;
if(treeListData.hasChildren)
{
setStyle(color,0xff0000);
setStyle(fontWeight,'bold');
}
else
{
setStyle(color,0x000000);
setStyle(fontWeight,'normal');
//覆盖updateDisplayList()方法
//设置每个树节点的文本。
覆盖保护函数updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(super.data)
{
if(treeListData.hasChildren)
{
var tmp:XMLList =
new XMLList(treeListData.item) ;
var myStr:int = tmp [0] .children()。length();
this.labelField.text = super.data。@ label +(+ myStr.toString()+);
}
}
}
]]>
< / fx:Script>
< s:Rect id =indentationSpacerwidth ={treeListData.indent}percentHeight =100alpha =0>
< s:fill>
< s:SolidColor color =0xFFFFFF/>
< / s:fill>
< / s:Rect>
< s:BitmapImage source ={treeListData.disclosureIcon}visible ={treeListData.hasChildren}/>
< / s:Group>
< s:BitmapImage source ={treeListData.icon}/>
< / s:HGroup>
< / s:HGroup>
< / s:MXTreeItemRenderer>
感谢David Goshadze的评论我能够解决问题。
这是我的新XML:
< notifications> ;
< root label =a>
< item label =moshe/>
< item label =moshe2/>
< / root>
< root label =b/>
< root label =c/>
< root label =d/>
< root label =e/>
< / notifications>
这是我的新渲染器:
<?xml version =1.0encoding =utf-8?>
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mx>
< s:州>
< s:国家名称=选定/>
< / s:州>
< fx:Script>
<![CDATA [
import com.flexer.Debug;
导入mx.controls.Alert;
覆盖公共函数集数据(value:Object):void {
super.data = value;
if(super.data){
if(treeListData.hasChildren)
{
setStyle(color,0xff0000);
setStyle(fontWeight,'bold');
}
else
{
setStyle(color,0x000000);
setStyle(fontWeight,'normal');
覆写保护函数createChildren():void
{
super.createChildren();
$ b //覆盖updateDisplayList()方法
//设置每个树节点的文本。
覆盖保护函数updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(super.data)
{
var val:XML = super.data as XML;
if(val.name()=='root'){
this.rootItemGroup.visible = true;
this.itemGroup.visible = false;
var tmp:XMLList =
new XMLList(treeListData.item);
var myStr:int = tmp [0] .children()。length();
this.labelField.text = super.data。@ label +(+ myStr.toString()+);
} else {
this.rootItemGroup.visible = false;
this.itemGroup.visible = true;
}
}
}
]]>
< / fx:Script>
< s:Rect id =indentationSpacerwidth ={treeListData.indent}percentHeight =100alpha =0>
< s:fill>
< s:SolidColor color =0xFFFFFF/>
< / s:fill>
< / s:Rect>
< s:BitmapImage source ={treeListData.disclosureIcon}visible ={treeListData.hasChildren}/>
< / s:Group>
< s:BitmapImage source ={treeListData.icon}/>
< / s:HGroup>
< / s:HGroup>
< / s:MXTreeItemRenderer>
如果我想检查一个项目是叶还是节点,我不能检查.hasChildren,因为我有叶节点。所以我检查XML对象的名称属性来弄清楚。
很好用!感谢您的帮助。
Using Flex 4.1, i'm trying to create a Tree element with a custom ItemRenderer (MXTreeItemRenderer). my problem is that whenever I fold and unfold a root item, the order of the items change.. it's weird like maybe the XML is not formatted properly.
any ideas?
my Main.mxml file:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<!-- Launch your application by right clicking within this class and select Debug As > FDT SWF Application -->
<fx:Declarations>
<fx:XML id="moshe">
<notifications>
<root label="a" state="root_item">
<node state="item" label="moshe"/>
<node state="item" label="moshe"/>
</root>
<root label="b" state="root_item"/>
<root label="c" state="root_item"/>
<root label="d" state="root_item"/>
<root label="e" state="root_item"/>
</notifications>
</fx:XML>
</fx:Declarations>
<mx:Tree dataProvider="{moshe}" width="500" itemRenderer="TheRenderer" labelField="@label" showRoot="false" folderClosedIcon="{null}" defaultLeafIcon="{null}"
folderOpenIcon="{null}" />
</s:Application>
and my Item Renderer:
<?xml version="1.0" encoding="utf-8"?>
<s:MXTreeItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:states>
<s:State name="normal" basedOn="{data.@state}"/>
<s:State name="hovered" basedOn="{data.@state}"/>
<s:State name="selected" basedOn="{data.@state}"/>
<s:State name="root_item"/>
<s:State name="item" />
</s:states>
<fx:Script>
<![CDATA[
import com.flexer.Debug;
import mx.controls.Alert;
override public function set data(value:Object):void {
super.data = value;
if(treeListData.hasChildren)
{
setStyle("color", 0xff0000);
setStyle("fontWeight", 'bold');
}
else
{
setStyle("color", 0x000000);
setStyle("fontWeight", 'normal');
}
}
// Override the updateDisplayList() method
// to set the text for each tree node.
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(super.data)
{
if(treeListData.hasChildren)
{
var tmp:XMLList =
new XMLList(treeListData.item);
var myStr:int = tmp[0].children().length();
this.labelField.text= super.data.@label + " (" + myStr.toString() + ")";
}
}
}
]]>
</fx:Script>
<s:HGroup left="0" right="0" top="0" bottom="0" verticalAlign="middle" includeIn="root_item">
<s:Rect id="indentationSpacer" width="{treeListData.indent}" percentHeight="100" alpha="0">
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
</s:Rect>
<s:Group id="disclosureGroup">
<s:BitmapImage source="{treeListData.disclosureIcon}" visible="{treeListData.hasChildren}" />
</s:Group>
<s:BitmapImage source="{treeListData.icon}" />
<s:Label id="labelField" text="{treeListData.label}" paddingTop="2"/>
</s:HGroup>
<s:HGroup includeIn="item">
<s:Label text="{treeListData.label}"/>
</s:HGroup>
</s:MXTreeItemRenderer>
thanks to David Goshadze's comment i was able to resolve the issue.
this is my new XML:
<notifications>
<root label="a">
<item label="moshe"/>
<item label="moshe2"/>
</root>
<root label="b" />
<root label="c" />
<root label="d" />
<root label="e" />
</notifications>
and this is my new renderer:
<?xml version="1.0" encoding="utf-8"?>
<s:MXTreeItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>
<fx:Script>
<![CDATA[
import com.flexer.Debug;
import mx.controls.Alert;
override public function set data(value:Object):void {
super.data = value;
if (super.data) {
if(treeListData.hasChildren)
{
setStyle("color", 0xff0000);
setStyle("fontWeight", 'bold');
}
else
{
setStyle("color", 0x000000);
setStyle("fontWeight", 'normal');
}
}
}
override protected function createChildren():void
{
super.createChildren();
}
// Override the updateDisplayList() method
// to set the text for each tree node.
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(super.data)
{
var val:XML = super.data as XML;
if (val.name() == 'root') {
this.rootItemGroup.visible=true;
this.itemGroup.visible=false;
var tmp:XMLList =
new XMLList(treeListData.item);
var myStr:int = tmp[0].children().length();
this.labelField.text= super.data.@label + " (" + myStr.toString() + ")";
} else {
this.rootItemGroup.visible=false;
this.itemGroup.visible=true;
}
}
}
]]>
</fx:Script>
<s:HGroup id="rootItemGroup" visible="false" left="0" right="0" top="0" bottom="0" verticalAlign="middle">
<s:Rect id="indentationSpacer" width="{treeListData.indent}" percentHeight="100" alpha="0">
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
</s:Rect>
<s:Group id="disclosureGroup">
<s:BitmapImage source="{treeListData.disclosureIcon}" visible="{treeListData.hasChildren}" />
</s:Group>
<s:BitmapImage source="{treeListData.icon}" />
<s:Label id="labelField" text="{treeListData.label}" paddingTop="2"/>
</s:HGroup>
<s:HGroup id="itemGroup" visible="false">
<s:Label text="item ->"/>
<s:Label text="{treeListData.label}"/>
</s:HGroup>
</s:MXTreeItemRenderer>
If i want to check if an item is a leaf or a node I cannot check .hasChildren because i have leafs with nodes. so i check the name attribute of the XML object to figure that out. works great! thanks for the assistance.
这篇关于flex4 mx |树 - 项目顺序改变,当我折叠和展开一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!