tree with contexmenu - add listeners for event

19 views
Skip to first unread message

Stanimir Marinov

unread,
Mar 6, 2015, 9:30:54 AM3/6/15
to struts2...@googlegroups.com
I have tree with contextmenu. How can I write with struts2-jquery plugin:
.on('changed.jstree'.. with ajax request like this: http://wp.wikirex.com/2014/04/13/contextmenu-plugin/
and this is complete example - view HTML source:
http://www.jstree.com/demo_sitebrowser/

I need to have simple generated from struts2 plugin JavaScript:
  $('#some_tree').on(...// listeners for event

<
sjt:tree
name="groupsTree"
id="groups_tree_id"
href="%{treeDataUrl}"
jstreetheme="apple"
onClickTopics="treeGroupsClicked"

contextmenu="{
items: {
'create' : {
'label': 'New',
'action': function (obj) { console.log(obj); this.create(obj); ajaxExec('%{editNode}', {'groupsId': obj[0].id,'editaction':1}); }
},
'rename' : {
'label': 'Rename',
'action': function (obj) { return { renameItem: this.rename(obj) }; }
},
'ccp' : {
'label': 'CCP',
'action': function (obj) { ajaxExec('%{editNode}', {'groupsId': obj[0].id,'editaction':3}); }
},
'remove' : {
'label': 'Delete',
'action': function (obj) { this.remove(obj); ajaxExec('%{editNode}', {'groupsId': obj[0].id,'editaction':0}); }
}
}
}"
/>

Stanimir Marinov

unread,
Mar 11, 2015, 6:23:58 AM3/11/15
to struts2...@googlegroups.com
Its better to have JavaScript with events and not to try with custom items in contextmenu ="{}"
https://github.com/vakata/jstree/issues/1030

elem.on('delete_node.jstree', function (event, data) {
console.log(event);
console.log(data);
}).on('create_node.jstree', function (event, data) {
console.log(data.rslt.parent.id);
ajaxExec(url, {'groupsId': data.rslt.parent.id, 'editAction': 2});
}).on('rename_node.jstree', function (event, data) {
console.log(data.rslt.obj[0].id);
console.log(data.rslt.name);
ajaxExec(url, {'groupsId': data.rslt.obj[0].id, 'name': data.rslt.name, 'editAction': 1});
}).on('move_node.jstree', function (event, data) {
console.log(event);
}).on('copy_node.jstree', function (event, data) {
console.log(event);
});
Reply all
Reply to author
Forward
0 new messages