JavaScript.CoolDev.Com Support Forums
Any questions related to JavaScript menu and JavaScript tree menu by Javascript.CoolDev.Com
| Author |
Message |
jj
Joined: 07 Jun 2007 Posts: 4 Location: US
|
Posted: Thu Jun 07, 2007 1:29 pm Post subject: dynamic tree updates client-side using cooltreePRO |
|
|
I'm trying to use the dynamic tree update features of coolTreePRO (v2.8.7), and am seeing some strange things happening. Is dynamic tree updating working? On the FAQ page, it says it is still in development, yet there's another page in the documentation section that includes an example of it working (which I used as a guide), so I'm not sure what the status is.
I'm building a "search results" tree based on a main tree, so my page has 2 separate trees on it. I "hide" one of the trees when the other one is active, and have had this working without a problem for a while.
I am building the search results tree by first dynamically removing it's previous contents with the following code snippet:
| Code: | for (var x = TREE_SEARCH.getRoot().getNumberOfChildren(); x > 0; x--)
{
var mix = TREE_SEARCH.getRoot().getChild(x-1).getMinorIndex();
TREE_SEARCH.getRoot().deleteNode(mix);
} |
Then I set up the new tree data one top-level node at a time in a string (NEWstnode), and make the following call for each top-level node string, incrementing stNewOffset for each one that gets added (it starts at 0):
| Code: | TREE_SEARCH.getRoot().addNode(stNewOffset, eval(NEWstnode));
|
This works the first couple times, but then it seems to break, giving me a java error in cooltreepro.js after making the addNode() call. The error in java console reads:
this._getLayer() has no properties
and references that call in the "with" test in the following function in cooltreepro.js:
| Code: | $._updateDimensions_gecko = function (_force)
{
if (!this.h || _force)
{
with (this._getLayer().childNodes[0])
{
this.w = offsetWidth;
this.h = offsetHeight;
}
if (this._tree._needAdvancedWrapping())
this._exceeds = this._tree._format.exp && this.h > this._tree._format.expimgsize[1];
}
} |
At that point, the search tree isn't displayable and I can't seem to get it back without reloading the page from the server.
Am I doing something wrong or is this a bug?
Thanks in advance!
JJ |
|
| Back to top |
|
 |
AlexKunin Developer
Joined: 03 Jan 2003 Posts: 1191
|
Posted: Fri Jun 08, 2007 9:07 am Post subject: |
|
|
I think you should try recreate() method:
| Code: | var NEW_TREE_NODES = [...];
tree.getRoot().recreate(NEW_TREE_NODES); |
|
|
| Back to top |
|
 |
jj
Joined: 07 Jun 2007 Posts: 4 Location: US
|
Posted: Fri Jun 08, 2007 2:03 pm Post subject: |
|
|
Thanks for the quick reply Alex.
Unfortunately, using recreate() yields a different javascript error:
_node[0] has no properties
and references the 2nd if test in $._prepareNode() in cooltreepro.js:
| Code: | $._prepareNode = function (_node)
{
if (_isUndefined(_node[_node.length - 1]))
_node = _node.slice(0, _node.length - 1);
if (_isUndefined(_node[0].id))
_node = ([{id:null}]).concat(_node);
if (_isUndefined(_node[4]) || _isUndefined(_node[4].format))
_node = _node.slice(0, 4).concat([{format:{}}]).concat(_node.slice(4));
. . .
. . .
. . .
|
It doesn't seem to matter if there's data in the old or the new tree, it yields the same error. And I'm verifying that the tree array is set up correctly prior to calling recreate().
But perusing the API, I think I may have found an alternative that not only alleviates us from having a second tree, but also allows us to remove any dynamic updating of trees.
I'm thinking we can just get by with our main tree, which never changes and contains a full set of information, and set the "search results tree" up by simply calling hideNode() for any nodes that don't match the search criteria. As long as we can call hideNode() on a top level node and have it hide the entire node (not just it's children, but the node as well), then this should be sufficient for our needs. Based on the documentation, this should work.
I'll post the results once I've tried this, but if we can do that, it will make our page much simpler, and get around the issues we're having trying to get dynamic tree manipulation to work.
Thx,
JJ |
|
| Back to top |
|
 |
jj
Joined: 07 Jun 2007 Posts: 4 Location: US
|
Posted: Fri Jun 08, 2007 3:30 pm Post subject: |
|
|
Apparently, even though it's documented in the API on this site, there is no "hideChildren()" function in the cooltreepro.js file (at least not for the latest version, v2.8.7).
Not sure why it's documented as a function in the API, but nonetheless, my workaround posted earlier isn't possible.
JJ |
|
| Back to top |
|
 |
jj
Joined: 07 Jun 2007 Posts: 4 Location: US
|
Posted: Fri Jun 08, 2007 5:44 pm Post subject: |
|
|
I played around a bit more and tried something that works using my original dynamic method of deleting and adding nodes.
Instead of deleting the whole tree from the root node and adding top level nodes to the root node, I added a "dummy" top level node and delete all the previous search result nodes, then add my nodes from the dummy top-level node instead of the root node. That appears to work fine.
So it appears that there may be a bug with the handling of the invisible root node within the dynamic tree functionality.
I'd prefer to not have to do it this way, but it works, so I'll go with it until the root node handling issues get resolved.
Thx,
JJ |
|
| Back to top |
|
 |
|
|