Is it possible to limit how deep the tree can go?

106 views
Skip to first unread message

boteeka

unread,
Apr 8, 2009, 10:02:43 AM4/8/09
to jsTree
I have a tree with folder nodes only on it. These nodes can be dragged
and dropped on each other. I want to limit the tree to be only two
levels deep, and so any drag-and-drop attempts which would make the
tree more deep would be disallowed. Is there a method to accomplish
this with the current featureset of jsTree 0.9.6?

vakata

unread,
Apr 8, 2009, 11:16:57 AM4/8/09
to jsTree
Yes, check the metadata (under "others" on the examples page) examples
- what you are looking for is "max_depth".

Best regards,
Ivan

boteeka

unread,
Apr 9, 2009, 3:44:20 AM4/9/09
to jsTree
Ok, that was dumb on my part not to look first. Sorry.

However, I looked on the examples. The difference is that I'm using
async JSON as source, and it doesn't seem to work. Here it is the JSON
response for the top level objects:
([
{
attributes: {id: 1},
state: 'closed',
data: 'Electronics',
mdata: { type: 'file', max_depth : 2 }
},
{
attributes: {id: 6},
state: 'closed',
data: 'Portable electronics',
mdata: { type: 'folder', max_depth : 2 }
}
])

In the rules attribute of the configuration I set metadata: "mdata".
Oh, and the metadata jquery plugin is loaded.

The problem is that it doesn't work at all. Even if I change the type
to file it doesn't show any difference.
Most probably I made some mistakes on the metadata part, but can't
figure it out what exactly.

vakata

unread,
Apr 9, 2009, 1:46:52 PM4/9/09
to jsTree
Hi,
I am sorry the metadata example was not available when I posted my
previous reply - you can take a look at it now:
http://www.jstree.com/reference/_examples/5_others.html (the second
example).

Basically you need this type of structure:
...
{
attributes: {id: 1, mdata : "{ type: 'file',
max_depth : 2 }" },
state: 'closed',
data: 'Electronics'
},
...

mdata becomes part of the attributes and its value is a string.

I hope this helps!
Best regards,
Ivan

Szász Botond

unread,
Apr 16, 2009, 2:03:54 AM4/16/09
to jst...@googlegroups.com
Hi,

Thanks for your guidance. I finally worked out. But I found that your example does not work:

...
       {
               attributes: {id: 1, mdata : "{ type: 'file',  max_depth : 2 }" },
               state: 'closed',
               data: 'Electronics'
       },
...

This example produces tree items like this:

<li class="closed last" id="4" }="" folder="" mdata="{ type : "><a class="" style="" href="#">LCD</a></li>

In order for this to work, the syntax for mdata needs to be like this:
mdata: '{ type: "folder", max_depth : 1 }'

The difference is the quotes used. Your example also gave a syntax error in jquery.metadata plugin.

I just thought it might be useful to know.

Thank you once again for your help and the great work you put in jsTree! Greatly appreciated.


2009/4/9 vakata <ivan.b...@gmail.com>



--
Szász Botond
   e-mail: bot...@gmail.com,
              bot...@yahoo.com
   tel.: +40744303363
Reply all
Reply to author
Forward
0 new messages