can the popular javascript tree views (jstree, dynatree…) be setup to read data from an adjacency model?

StackOverflow https://stackoverflow.com/questions/8991899

Question

can the popular javascript tree views (jstree, dynatree...) be setup to read data from an adjacency model? say I have a table with classId, ClassName,ClassType,ParentClassId how can i fetch data for say the dynatree? considering the json expected by dyna tree should something like below

        {title: "Class1"},
        {title: "Class2", isFolder: true,
            children: [
                {title: "Class4"},
                {title: "Class5"}
            ]
        },
        {title: "Class3"}

I am using an asp.net asmx web service with linq to sql at the backend

Was it helpful?

Solution

The only thing you have to do to have nodes loaded on demand is to add "state" : "closed" to the nodes whose child nodes are going to be loaded on demand.

You can have all your necessary attributes classId, ClassName,ClassType,ParentClassId attached to the node so then you can pass it through via ajax. ur code

"json_data": {
      //elements to be displayed on the first load
      //everything with state = closed will be populated via ajax. 
      //         Note the ajax arguments

    "data": [{"data":'Class 1',
              "attr":{"id":'kit1',
                      "ClassName":"ClassName",
                      "classId":"classId"},
              "state" : "closed"},
             {"data":'Class 2',
              "attr":{"id":'kit2',
                      "ClassName":"ClassName",
                      "classId":"classId"},
              "state" : "closed"}
            ],
    "ajax" : {
        url : "http://localhost/introspection/introspection/product",
        data : function(n) {
                 return {
                   "classId":$.trim(n.attr('classId')),
                   "ClassName":$.trim(n.attr('ClassName')),
                 }
               }
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top