jQWidgets Forums
jQuery UI Widgets › Forums › Navigation › Tree › Problem with Ajax Tree Demo
This topic contains 4 replies, has 3 voices, and was last updated by lee-da 12 years, 4 months ago.
-
Author
-
Hi,
I’m using your “Load on Demand with Ajax” Demo for creating a dynamic Tree with PHP. My problem now is that your method only works for the first level. As soon as the second level is loaded (with new “Loading…” subitems) another expand click on the parent element now loads the subitems of the first item in level 2. This is due to .find(“li”). And now these subitems are appended to the parent element.
Wrong:
Level1-1
Level1-2
Level2-1
– Level2-2
– Level3-1 (loaded after expanding Level1-2 twice)Right:
Level1-1
Level1-2
– Level2-1
– Level3-1 (loaded after expanding Level2-1)
– Level2-2So, I modified your script to stop loading subitems if the element’s parent is not equal to the expanded item (excludes levels >1):
tree.on('expand', function(event) { var $element = $(event.args.element); var children = $element.find('li'); $.each(children, function() { var item = tree.jqxTree('getItem', this); if (item.label == 'Loading...'&&item.parentElement==$element[0]) { $.getJSON('data.php',{ load: 'leaf', id: item.value }, function(data){ tree.jqxTree('addTo', data, $element[0]); tree.jqxTree('removeItem', item.element); }); return; }; });});
Now my question:
Is there a way to simplify this a bit? Is there maybe a jqxTree method to access only first level items?
Or could removing the “expand” binding for already-loaded items be a good approach?
Thanks.
Hi lee-da,
There is already a post about that: http://www.jqwidgets.com/community/topic/jqxtree-load-on-demand-with-ajax-re-open-issue/
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Thanks. I’ll give that “ul:first” thing a try.
Btw, do you plan to implement a forum search? This could be more precise than Google – or maybe a Google plugin, for instance?
@Community:
For the time being, googling “site:jqwidgets.com/community <your keywords>” gives quite good results.
Hi lee-da,
There is already Forum Search. When you login into your account, there is a search icon at the top-right corner of your screen. When you click it, a search field will be displayed.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Ok, a little unobtrusive – but it works.
Thanks.
-
AuthorPosts
You must be logged in to reply to this topic.