Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of Manoj Patil
Manoj Patil🇮🇳

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

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Leonidas DosasLeonidas Dosas🇬🇷

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

Avatar of Manoj PatilManoj 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 leakim971leakim971🇬🇵

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Manoj PatilManoj Patil🇮🇳

ASKER

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 ?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


ASKER CERTIFIED SOLUTION
Avatar of Manoj PatilManoj Patil🇮🇳

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Manoj PatilManoj Patil🇮🇳

ASKER

The code posted by me is working for me.
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.