r p

r p

  • NA
  • 343
  • 0

How to fetch sql data and covert to jquery object?

Nov 15 2013 4:46 PM
I have the hierarchy of an organization in the SQL database. It looks like this -

Main Manager
Manager - 1
Manager - 1.1
Manager - 1.1.1
Manager - 2
Manager - 2.1
Manager - 2.1.1
Manager - 2.2

etc.

I want to fetch the values in the database and convert to a jquery object just like the example below.
How can I fetch the sql data in the database in hierarchical order and create a jquery object like in the example below?

var data = { Name: "Manager - 1",
                  ID: "1",

                children: [ { 

                                  Name: "Manager - 1.1",
                                   ID: "1.1",
                                     children: [ { 
                                              Name: "Manager - 1.1.1",
                                         ID: "1.1.1"}
                     ]
                  Name: "Manager - 1.2",
ID: "1.2",
children: [ { 
Name: "Manager - 1.2.1",
ID: "1"}
]
}
]
};

Answers (7)