Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: open tree Item by JS (and not user click)
hpbauer
Member

Posts: 12
Registered: 7/2/2004
Member Is Offline
posted on 7/2/2004 at 01:52 PM Reply With Quote
open tree Item by JS (and not user click)


I want to open a special tree item by Javascript,
e.g. I have the following menu tree:
var test_tree = [
['level0','',
['level1','',
['level2','',
['Item1',''],
['Item2',''],
],
],
],
];
How can I say in javascript: a??open tree to show item1a??, which means to open level2.
A approch might be the following call of the function trees().toggle():
trees(0).toggle(0); //open level0, but what, if level0 is opened than it will be closed
trees(0).toggle(1);
trees(0).toggle(2);

How can I find out, that I have to call trees(0).toggle(2) the open parent item of item1?
View User's Profile View All Posts By User U2U Member
rock
Moderator

Posts: 687
Registered: 4/15/2003
Member Is Offline
posted on 7/2/2004 at 03:50 PM Reply With Quote

Each tree item object has o_parent property. So in your example Item1 has o_parent level2 item, level2 item has o_parent level2 item, so on.
View User's Profile View All Posts By User U2U Member
hpbauer
Member

Posts: 12
Registered: 7/2/2004
Member Is Offline
posted on 7/2/2004 at 05:20 PM Reply With Quote
and how can i access the item?


About this functionallity I have found out,too. So I implemented a new feature:
this.rootPath, where I stored the references to all the items a level above. In my example the references to the objects "level2", "level1", "level0".
If I decide now to open item2 via JS, how can I get the reference to this object?
(Than I can walk throw my Array and open the tree!)
Thanks,
PETER
View User's Profile View All Posts By User U2U Member
rock
Moderator

Posts: 687
Registered: 4/15/2003
Member Is Offline
posted on 7/5/2004 at 09:38 AM Reply With Quote

Reference to item2 object you could get by index of the item in the a_index array (member of the tree object).
o_item = o_tree.a_index[n]; // where n is index of item2
o_parent = o_item.o_parent; //reference to parent item - level2;
o_parent1 = o_parent.o_parent; //reference to parent item - level1;
...
View User's Profile View All Posts By User U2U Member
hpbauer
Member

Posts: 12
Registered: 7/2/2004
Member Is Offline
posted on 7/5/2004 at 10:19 AM Reply With Quote
but how can I open a Item


First of all, thank you for your reply. But I've got another question. How can I open a menu entry?
I know the object and the n_id. I tried the function item_open. There references to the currend object are needed. So I tried to implement a owne function item_open:
I copied the source code and replaced the "this" against a variable that stores the object i want to open. But this does not work.

Furthor I tried to open it with the toggle function. But a Javascript-Call like
<script>
trees[t_id].toggle(3);
</script>
dosn't work, too.
Thank you for help,
PETER
View User's Profile View All Posts By User U2U Member
hpbauer
Member

Posts: 12
Registered: 7/2/2004
Member Is Offline
posted on 7/5/2004 at 11:41 AM Reply With Quote
more details...


I tried to open the tree very similar to the Forum thread http://www.softcomplex.com/forum/viewthread.php?tid=290
[...]
for (var i = 1; i < this.a_index.length; i++)
this.toggle(i);
[...]

But I only want to open the path to a specal item.
[...]
for(var i=0; i<rootPath.length;i++){
this.toggle(rootPath.n_id);
}

So why does it not open? rootPath is a array where i stored all predecessors of the Element. rootPath[0] is the rootElement, rootPath[1] is the child on the way down, and so on.
View User's Profile View All Posts By User U2U Member
rock
Moderator

Posts: 687
Registered: 4/15/2003
Member Is Offline
posted on 7/5/2004 at 12:01 PM Reply With Quote

So you need to collect into some array all direct item's parents (use o_parent member of each item recursively) and call their open method.
View User's Profile View All Posts By User U2U Member
hpbauer
Member

Posts: 12
Registered: 7/2/2004
Member Is Offline
posted on 7/5/2004 at 12:16 PM Reply With Quote

my coding at the end of the tree fkt looks like this:
for (var i = 0; i < startItem.rootPath.length; i++) {
var open_n_id=startItem.rootPath.n_id;

if(!startItem.rootPath.b_opened) {
alert("this.toggle("+open_n_id+"ni="+i);
this.toggle(startItem.rootPath.n_id);
alert("done";
} //of if
} //of for

But it does not work.
-Type of startItem is Object. It stores the Object of the MenuItem I want to open.

-rootPath is a Array that stores all the parents of start startItem. It starts with the root (
for(var i=0;i<startItem.rootPath.length; i++)
alert(startItem.rootPath.n_id);
)
returns 0,1,2;

I think there's something wrong on my if (!...b_opened). But I need to check, weather a parent Element is opened or not. Because if it is opened, the call toggle(...) will close it, won't it?
Thank you for your help!
View User's Profile View All Posts By User U2U Member
hpbauer
Member

Posts: 12
Registered: 7/2/2004
Member Is Offline
posted on 7/5/2004 at 12:27 PM Reply With Quote
Problem solved. Thank you for your help!


Thank you for your help. I could solve the problem. I made some silly mistake. All coding described above is perfectly correct!
View User's Profile View All Posts By User U2U Member
rock
Moderator

Posts: 687
Registered: 4/15/2003
Member Is Offline
posted on 7/5/2004 at 12:28 PM Reply With Quote

If the rootPath array really holds all direct parents of the particular item you need to call open method in reverse direction, i.e. at the begging open topest parents:
for (var i = startItem.rootPath.length-1; i>=0; i++) { ... };
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:
Tigra Tree Menu
Product Demonstrations Live Demos:
Frames targeting
Win help style
Free Download Free Download
Free Download Menu Builders
Online Builder
Product Documentation Documentation:
Documenation Page
Support Forum Technical Support
Support Forum
   
Tigra Tree Menu PRO
Product Demonstrations Live Demos
Multiple Trees
Frames Targeting
Icons and Styles Overloading
Event Handling
Performance Test
Version 1.2 features
Product Documentation Documentation
Documenation Page
Change Log
Support Forum Technical Support
Support Forum
Customer Care System
Order Now ORDER NOW!
Add to Cart
View Cart
 

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004