Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6118535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:26:53+00:00 2026-05-23T15:26:53+00:00

I have to retrieve a list of menu item from a database and display

  • 0

I have to retrieve a list of menu item from a database and display it in a tree structure
I want to use the menu name as the node name and menu id as the id of the node.
The method I used was to retrieve the data using an ajax call and put them into a list and then display it as a tree.But I think dynamically creating nodes depending on the data is more efficient.

   function createNodeList(){
        $('#menuCPanel #contentData #tree').jstree({            
            "json_data" : {
                /*"data" : [{
                    "data" : {title : "menuName"},
                    "attr" : {id : "menuId"},
                    "state" : "closed"
                    }
                   ],*/
                 "ajax" :{
                    "type" : "POST",
                    "url" : "?m=admin?action=getNodeList",
                    "dataType" : "json",
                    "data" : function(result){
                        return {                            
                            id : result.attr ? result.attr("id") : result['menuId'],
                            title : result.attr ? result.attr("title") : result['menuName']
                        };
                    },  

                },
            },
            "callback" : {

            },

            "themes" : {
                "theme" : "classic",
                "dots" : true,
                "icons" : true
            },
            "plugins" : ["json_data", "themes"]

        }).bind("select_node.jstree", function (e, data) { alert(jQuery.data(data.rslt.obj[0], "jstree").id) });

    }


    }

this is the stucture of my json data

"data":[{"menuId":"1","menuName":"Top Menu"},{"menuId":"2","menuName":"Main Menu"},{"menuId":"3","menuName":"Bottom Menu"},{"menuId":"4","menuName":"Main Menu"}]}

I would like to know what is wrong with the above result and how to dynamically create a node within in the ajax.success();
I went through some examples but all of them use the jstree.cretate() which i can’t invoke inside jstree.json_data.ajax.success()
thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:26:54+00:00Added an answer on May 23, 2026 at 3:26 pm

    This is a standard jstree with json data, which also binds select_node to do actions when a node is selected. Nodes must not have an ID which are plain numbers or contain jquery special selector characters. Number IDs must have a standard character first. so 1 should be N1, 2 should be N2 for example.

    $('#MyTreeDiv').jstree({
            "json_data": {
                "ajax": {
                    "type": "POST",
                    "url": "/MyServerPage.aspx?Action=GetNodes",
                    "data": function (n) { return { id: n.attr ? n.attr("id") : 0} },
                }
            },
            "themes": {
                "theme": "default",
                "url": "/Content/Styles/JSTree.css",
                "dots": false
            },
            "plugins": ["themes", "json_data", "ui", "crrm"]
        }).bind("select_node.jstree", function (e, data) {
            var selectedObj = data.rslt.obj;
            alert(selectedObj.attr("id"));
    });
    

    The json returned from your server must be in the correct format as defined in the jstree documentation, and must no include several special characters, unless those characters are escaped or the json created using serialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of record Id's that I want to retrieve from Sql
I have a layout with an extension method that takes a list of menu
I have retrieve JSON from my controller of asp.net mvc : {ja: [ {Name:ABC1,PictureName1:my
I have an app where I retrieve a list of users from a specific
I have two tables containing Tasks and Notes, and want to retrieve a list
I am trying to use the Directory.GetFiles() method to retrieve a list of files
I have to retrieve all the items from a list based on the condition
I have the following method that should retrieve a list of loaded local (in
I have generic list which must be a preserved order so I can retrieve
I have a PHP script that retrieves list of urls from a site and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.