That is a very poor sample app:
1) the xml file is not valid, multiple mismatched start-end tags
2) The mxml file is invalid, comments before the <?xml> tag
3) The model source path and filename are wrong
Next time, please run the sample to make
sure it works. Also I do not see an implementation of any of the
suggestions I made, like “labelFunction”. If it had not been
so easy to fix, I would have quickly stopped trying.
Now, before we look at labelFunction,
there is a larger issue. Your source xml has more nodes in it than your desired
tree structure. The tree will faithfully render all the nodes in the source
xml, and we cannot control that directly. So the tree dataProvider XML
will need to be built using the source xml.
You can do this on the server, (manually,
or using XSLT, if you have the necessary skills), or you can do it in action script
on the client. Client side, you will be recursively traversing the xml
tree and conditionally building an xml string for your tree dataProvider, or
building it out of TreeNode objects.
In the mean time, below is your sample app
modified to use a labelFunction that simply displays the xml with tags as
labels for the element nodes and the node value for the text nodes. Note
that I changed mx:Model to mx:XML
Tracy
<?xml version="1.0"
encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Script><![CDATA[
//labelFunction
private
function lfTree(oNode:XMLNode):String
{
var
sNodeType:String = oNode.nodeType.toString();
if
(sNodeType == "3") { //3
indicates a text node
return
oNode.nodeValue;;
}
else
{ //1
is an element node
return
oNode.nodeName;
}
}//lfTree
]]></mx:Script>
<mx:XML
id="DocumentMaster" source="DocumentMaster.xml"/>
<mx:VBox
height="100%">
<mx:Tree
id="myTree" height="100%" width="100%"
labelFunction="lfTree"
>
<mx:dataProvider>
{DocumentMaster}
</mx:dataProvider>
</mx:Tree>
</mx:VBox>
</mx:Application>
Thanks for your help
Tracy.
I tried what you told me below and I still could not get it to work. I have
enclosed and attached a brief example if someone has a minute to help me out,
it would be much appreciated, and I will repay the favor briefly when I send
out some examples to the group on bringing 3D aspects to Flex GUI's.
Here is my problem:
I need to Display in a tree:
document Name
ModuleName
RName
These three fields would be the Label
and for the data fields I would be using
DMKey
MOKey
RSKey
So in a perfect XML world my XML file would look like this:
I need to Display in a tree:
DocumentName
ModuleName
RName
These three fields would be the Label and for the data fields I would be using:
DMKey
MOKey
RSKey
So in a perfect XML world my file would look like this:
<node>
<node label="Doc Type 1" data="">
<node label="Module 1 Name"
data="">
<node
label="R Name 1" data="" />
<node label="R
Name 2" data="" />
</node>
</node>
</node>
Origanal Message
Hi all,
Can someone please help me out using the Flex tree
labelFunction. I have a massive XML document with no
labels specified. I need to right a function that
grabs only nodes and display them within my tree
control.
Thank you in advance. Much Appreciated.
-Augie
//Code Below and Attached
***********************************tree.mxml*************************************************************
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:VBox height="100%">
<mx:Model id="DocumentMaster"
source="DocumentMaster2.xml"/>
<mx:Tree id="myTree"
height="100%" width="100%"
borderStyle="none" >
<mx:dataProvider>
{DocumentMaster}
</mx:dataProvider>
</mx:Tree>
</mx:VBox>
</mx:Application>
*************************************DocumentMaster.xml******************************************
<DocumentMaster>
<DMKey>1</DMKey>
<DocumentType>Doc Type
1</DocumentType>
<DocumentSubType>DOc Sub Type
1 </DocumentSubType>
<DocumentName>Document One Name
1</DocumentName>
<DocumentNumber>12345</DocumentNumber>
<Modules>
<MOKey>1</MOKey>
<DMKey>1</DMKey>
<ModuleName>Module 1 Name</ModuleName>
<ModuleOrder>1</ModuleOrder>
<ModuleStatus>Active</ModuleStatus>
<RSets>
<RSKey>1</RSKey>
<MOKey>1</MOKey>
<RType>Action</RType>
<RName>R Name 1</RuName>
<RuleStatus>Active 1</RStatus>
<ROrder>1</ROrder>
</RuleSets>
<RSets>
<RSKey>2</RSKey>
<MOKey>1</MOKey>
<RType>Action 2</RType>
<RName>R Name 2</RName>
<RStatus>Active 2</RStatus>
<ROrder>2</ROrder>
</RSets>
<RSets>
<RSKey>3</RSKey>
<MOKey>1</MOKey>
<RType>Action 3</RType>
<RName>R Name 3</RuName>
<RStatus>Active 3</RStatus>
<ROrder>3</ROrder>
</RSets>
</Modules>
</DocumentMaster>
<DocumentMaster>
<DMKey>2</DMKey>
<DocumentType>Doc Type
2</DocumentType>
<DocumentSubType>DOc Sub Type
2 </DocumentSubType>
<DocumentName>Document Two
Name 2</DocumentName>
<DocumentNumber>6789</DocumentNumber>
<Modules>
<MOKey>1</MOKey>
<DMKey>2</DMKey>
<ModuleName>Module Two Name</ModuleName>
<ModuleOrder>1</ModuleOrder>
<ModuleStatus>Active</ModuleStatus>
<RSets>
<RSKey>1</RSKey>
<MOKey>2</MOKey>
<RType>Action</RType>
<RName>R Name 1</RuName>
<RuleStatus>Active 1</RStatus>
<ROrder>1</ROrder>
</RSets>
<RSets>
<RSKey>2</RSKey>
<MOKey>2</MOKey>
<RType>Action 2</RType>
<RName>R Name 2</RName>
<RStatus>Active 2</RStatus>
<ROrder>2</ROrder>
</RSets>
<RSets>
<RSKey>3</RSKey>
<MOKey>2</MOKey>
<RType>Action 3</RType>
<RName>R Name 3</RuName>
<RStatus>Active 3</RStatus>
<ROrder>3</ROrder>
</RSets>
</Modules>
</DocumentMaster>
*********************************** End
*******************************************************
Thank You
On 10/3/05, Tracy Spratt <[EMAIL PROTECTED]> wrote:
When working with trees,
I prefer to set my data service call to
resultFormat="xml".
Then, in the label function, you can use the familiar xml class methods
and properties to define your label.
resultFormat defaults to "object" and Flex converts the xml into an
mx:Object. If you are comfortable with this you can leave the result
type alone and use dot notation to access the data you want for your
label.
When you select a node in the tree (resultFormat=xml), the
tree.selectedNode will be a reference to the xml node that produced it.
Access it with xml class members or using the TreeDataProvider api.
Tracy
-----Original Message-----
From: [email protected]
[mailto:[email protected]]
On
Behalf Of Augie
Sent: Monday, October 03, 2005 4:10 PM
To: [email protected]
Subject: [flexcoders] Flex tree labelFunction Help
Hi all,
Can someone please help me out using the Flex tree
labelFunction. I have a massive XML document with no
labels specified. I need to right a function that
grabs only nodes and display them within my tree
control.
Thank you in advance. Much Appreciated.
-Augie
______________________________________________________
Yahoo! for Good
Donate to the Hurricane Katrina relief effort.
http://store.yahoo.com/redcross-donate3/
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
YAHOO! GROUPS LINKS