vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.12k stars 1.38k forks source link

jsTree node loses an attribute when calling _get_json() #209

Closed antgel closed 12 years ago

antgel commented 12 years ago

My tree works fine, and I use something like: $("#tree").jstree.bind("select_node.jstree", function (event, data) { $.jstree._reference("#tree").destroy(); draw_tree(data.inst.get_json()); })

in order to redraw the tree, making the selected node the new root node. However, I'm experiencing weird behaviour. I narrowed it down by looking at my original root node and what get_json returns. I've pasted both below. You can see that data.attr.class isn't available, as data.attr is empty. I think this is a bug - please advise. NB I tried looking at get_json() in the source but it is somewhat beyond my Javascript abilities.

Dumper(root_node)
"{
 'data' => {
            'title' => 'United Medical',
            'attr' => {
                       'class' => 'tree-company'
                      }
           },
 'children' => [
                {
                 'data' => {
                            'title' => 'Patricia Jones',
                            'attr' => {
                                       'class' => 'tree-employee'
                                      },
                            'icon' => '/img/employee_by_id/432410.png'
                           },
                 'metadata' => {
                                'mobile_model' => '9700',
                                'mobile_serial' => '432532455325',
                                'mobile_name' => 'Blackberry Storm',
                               }
                }
               ]
}"

Dumper(root_node)
"[
 {
  'data' => {
             'attr' => {},
             'title' => 'Patricia Jones',
             'icon' => 'http://localhost:8080/img/employee_by_id/432410.png'
            },
  'attr' => {},
  'metadata' => {
                 'mobile_model' => '9700',
                 'mobile_serial' => '432532455325',
                 'mobile_name' => 'Blackberry Storm',
                }
 }
]"
vakata commented 12 years ago

This code is changed in v.1.0 and is more robust, but anyway - I believe in your case the class is set on the A element, so in order to get this class back you need to use: get_json( ..., ..., ['class']);

As mentioned here: http://www.jstree.com/documentation/json_data#get_json