-
FEATURED COMPONENTS
First time here? Check out the FAQ!
we offen have the database like this structure if the date is in tree structure.
it should be something as below:
==================================================
MyObject o1_1 = new MyObject("2", "node1.1", "010100", false);
List<SimpleTreeNode> node1_1_children = new ArrayList<SimpleTreeNode>();
node1_1_children.add(stn1_1_1); // skip
node1_1_children.add(stn1_1_2); // skip
SimpleTreeNode stn1_1= new SimpleTreeNode(o1_1, node1_1_children);
MyObject root = new MyObject("1", "node1", "010000", false);
List<SimpleTreeNode> rootChildrenList = new ArrayList<SimpleTreeNode>();
rootChildrenList.add(stn1_1);
rootChildrenList.add(stn1_2); // skip
rootChildrenList.add(stn1_3); // skip
SimpleTreeNode stn1= new SimpleTreeNode(root, rootChildrenList);
simpleTreeModel = new SimpleTreeModel(stn1);
Cheers,
Nathan
Thank you ,nathan.
but your code also fill the lowest chidren-node first,the root node last.
usually we have the data store in above structure in database. so it's easy to get it by "select * from tablename orderby layer".and if we read the Resultset from index 0 to last,it's easy to get the text to form a tree in text appearance(show like above).
but i want to use the tree appearance.Is it possible to fill a tree in this order ?not from lowest chidren-node to root node, but in the order i listed above.that is:
first fill:node 1
then fill: node 1.1
then: node 1.1.1
then:node 1.l.2
then:node 1.2
…………
why need this ?beacause we read it from ResultSet in this order,it's convienence to fill a tree in the same loop as read ResultSet.And if in this order, it's not neccessary to choose out children-nodes in every level.
in another word,if fill a tree like SimpleTreeNode does,it neccessary to choose out the lowest children-node first.then chooose out every level's children-node.and last the root node.(e.g. in the code above , we have to choose out node 1.1.1, node 1.1.2 first)
thanks.
i guess this can be done by a recursive function, isn't it??
Thanks for advise,i'll have a try.
I've got it work!
our zk is so strong that we even havn't to consider the tree order.
(i could del the layer now for its unuseness.)
Thanks very much, nathan!
friend how are you I am in a case like yours and I wonder if I could share the recursive function q've done'm in a dilemma and I'm very confused ... I know this topic this since 2009 but I'm new ZK .. help me Please ... my email is [email protected] I certainly do not speak much English because I'm Latin, well I appreciate any help you much
Asked: 2009-01-16 01:54:12 +0800
Seen: 236 times
Last updated: Aug 07 '15