(ej-tree-view) I want to know the value of the parent nodes of the currently selected node.

<ej-tree-view id="tagtree" node-select="onSelect">
                                            <e-tree-view-fields dataSource="ViewBag.data" id="id" parent-id="pid" text="name" expanded="expanded" has-child="hasChild" selected="selected"></e-tree-view-fields>
                                        </ej-tree-view>



    <script type="text/javascript">
 function onSelect() {
            var parray = new Array();
            //var nparent = this.getExpandedNodes()
            //var nparent = this.getCheckedNodes()
            var nparent = this.getVisibleNodes()
            var nseleted = this.getSelectedNode()

            //for (i = 0; i < nparent.length; i++) {
            //    parray[i]  = nparent[i].id
            //}
            //var a = nparent[0].id
            //var b = nparent[1].id
            var nodeseleted = nseleted[0].id
            var obj = { parray, nodeseleted };
            $.ajax({
                type: 'POST',
                url: '/TagInfo/getTreeNode',
                dataType: "json",
                data: obj
            });
        }

    </script>


==============================================
node1 
        node2
                node3 
node4
      node5
node6
node7


If node 3 is selected, can I know the data for node 1 and node 2?
i have to use ej.
thanks.


3 Replies 1 reply marked as answer

KR Keerthana Rajendran Syncfusion Team April 9, 2021 08:28 AM UTC

Hi Kimdoyoon, 
 
Thanks for contacting Syncfusion support. 
 
We checked your requirement to get the parent node details for the current selected node in EJ1 TreeView. We suggest you to get the required details using getParent() method by passing the id of selected node through node select event. Also, getTreeData() method returns the updated dataSource of corresponding node id passed as parameter.  
 
Refer to the following code 
 
function onSelect(args) { 
         var parentNode = this.getParent(args.id);// get parent details 
         var treeData = this.getTreeData(args.parentId); //get updated dataSource 
         console.log(parentNode); 
         console.log(treeData); 
      } 
 
 
The same code can be used within nodeSelect event of your Asp.Net Core application.  
 
Refer to the following links for more details on EJ1 TreeView component. 
 
 
 
 
Please let us know if you need further assistance.  
 
Regards, 
Keerthana.  
 
 


Marked as answer

KI kimdoyoon April 12, 2021 07:05 AM UTC

Thank you. The example described works very well!!!


KR Keerthana Rajendran Syncfusion Team April 13, 2021 05:49 AM UTC

Hi Kimdoyoon,  
 
Most welcome. We are glad to know that the provided example helped you. Please get back to us if you need further assistance.  
 
Regards, 
Keerthana.   


Loader.
Up arrow icon