how to set visible a node of a specific type

727 views
Skip to first unread message

Jonatan

unread,
Jul 7, 2010, 7:23:58 AM7/7/10
to jsTree
Hy there:
At the old version, i used the option visible to show some option of
the context menu only for some kind of types:
create : {
label : "Nuevo",
visible : function (NODE, TREE_OBJ) {
if(TREE_OBJ.get_type(NODE) == "N3") return -1;
},
But i can’t do the same on the new version:

"visible": function(obj,e) {
...
return -1;
}
And i can’t find it at new documentation.

Any help appreciated

Thanks!

ChrisR

unread,
Jul 7, 2010, 9:00:32 AM7/7/10
to jsTree
Hi,

You can find here: http://www.jstree.com/documentation/contextmenu
information, that 'items' expects object or function. The function
receives right clicked node and should return object in format as
described in above docs.
The configuration might look like this:

contextmenu: {
items: function (NODE, TREE_OBJ) {
var obj = {};
if ('type1' == NODE.attr('rel')) {
obj['create'] = {
label: 'Create',
action: function() {/*...*/},
//...
}
}
if ('type2' == NODE.attr('rel')) {
obj['rename'] = {
label: 'Rename',
action: function() {/*...*/},
//...
}
}
if ('type2' == NODE.attr('rel') || 'type3' ==
NODE.attr('rel')) {
obj['some_other_action'] = {
label: 'Some other action',
action: function() {/*...*/},
//...
}
}
// etc.
}
return obj;
}

Best regards,
ChrisRaven

vakata

unread,
Jul 7, 2010, 12:50:30 PM7/7/10
to jsTree
And also each of those items can have a property "_disabled" set to
true, which will render the item but it won't be clickable:

obj['rename'] = {
label: 'Rename',
action: function() {/*...*/},
_disabled : true,
//...
}

Kindest regards,
Ivan

Message has been deleted

Niyak

unread,
Jul 19, 2010, 3:23:14 AM7/19/10
to jsTree
Just for completion: The function only gets passed one parameter NODE,
however the tree is accesible via "this" (TREE_OBJ = this).
Reply all
Reply to author
Forward
0 new messages