Link to home
Start Free TrialLog in
Avatar of Manoj Patil
Manoj PatilFlag for India

asked on

JSTree Parent Node Text

Hello Experts,
I am using JSTree plugin to display my Data.
But when I select the Child node, I wanted to get the Parent node Text on form submit.
I have tried below code.

$(document).on('click', '#btnSubmit', function () {
var parent = [];
        var selectedElms =$js('#IndustryTree').jstree("get_selected", true);
        $.each(selectedElms, function () {
            selectedElmsIds.push(this.text);
            //parent.push(this.parent);            
            var node = $js('#IndustryTree').jstree(true).get_node(this.parent, true);            
            var Parentnode = $js('#IndustryTree').find("[id='" + this.parent + "']");
            parent.push(Parentnode[0].innerText);
        });
});

Open in new window

But When I run this code, in Parentnode[0].innerText I am getting Parent Node text as well as all Child node text. So it is difficult to differentiate the Parent Node Text.

Another issue is when Checked the Parent node, then all child nodes are selected. But I am not getting that selected parent node using below code

var selectedElms =$js('#IndustryTree').jstree("get_selected", true);

User generated image

This code is working when I particularly select the Child node, in this case, parent node CSS class will be jstree-icon jstree-checkbox jstree-undetermined

User generated image
Any help would be appreciated
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Can you post a piece of the HTML code to work more efficiently?
Avatar of Manoj Patil

ASKER

Hi,
I am binding the values from server side in .NET MVC.
So there is just a div to generate the tree.
The main operation is in javascript
SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
I got the Parent node now when I select the Child node instead of Parent Node.

Now, when I am selecting the Parent node directly, all the child node are selecting, But I am not getting the text values of parent as well as child nodes

How can I get it ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The code posted by me is working for me.