jQWidgets Forums

jQuery UI Widgets Forums Navigation Tree Get root value

This topic contains 2 replies, has 2 voices, and was last updated by  Titanium 11 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Get root value #48918

    Titanium
    Participant

    Hello,

    After multiple search and did not find my happiness, I just ask you a question.
    How to get the value of the root of a tree by selecting a child?

    Get root value #48921

    Peter Stoev
    Keymaster

    Hi Titanium,

    Unfortunately, there’s no available API for that. You can however get the parentElement from an item by using the item’s parentElement property. Then you can call the “getItem” method passing the parentElement and get its parentElement and so on until the parentElement is null. When it is null, that means that you found the “root” item.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Get root value #48925

    Titanium
    Participant

    Thank you for your answer, i could make this

    	$('#Tree').on('select',function(event) {
    		var args = event.args;
    		var item = $('#Tree').jqxTree('getItem', args.element);
    		var lastitem = item;
    		var parentitem;
    
    		while(true)	{
    			parentitem = $('#Tree').jqxTree('getItem', lastitem.parentElement);
    			
    			if (parentitem != null)
    				lastitem = parentitem;
    			else
    				break;
    		}
    		console.log(lastitem.value);
    	});

    It works well, it could be useful to another person.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.