I create a treeview using jsTree with contextmenu in asp.net mvc3.
<div id="divtree">
<ul id="tree">
<li><a href="#" class="usr">@Model.Name</a>
@Html.Partial("Childrens", Model)
</li>
</ul>
<script type="text/javascript">
$(function () {
$("#divtree").jstree(
{
"plugins": ["themes", "html_data", "ui", "crrm", "contextmenu"]
});
});
it's works fine.
I want to create a custome item in the context menu. for example create a new menu item. New for create new Employee in the context menu. and insert the employee in DB. I use a jQuery POST function for this task. But how to handle the click event in the
Context menu item.
Please help
Here's how you could customize the contextmenu plugin:
Alright, in this example I am only calling the base function inside the click handlers:
this.create(obj);
,this.rename(obj);
andthis.remove(obj);
whereobj
will be the node that was clicked.So now for example if you want to send an AJAX request to the server when a new item is added you could subscribe to the
create.jstree
event as shown in thedemo page
of the jsTree documentation:Inspect the
e
anddata
arguments that are passed to thecreate.jstree
event callback. They contain lots of useful information about the newly created node that you could use to send along with the AJAX request.Inspired by this example you could continue extending it with the
remove.jstree
andrename.jstree
events as shown in the documentation. So when you look at it, all that was needed was to read the documentation. For example I've never used jsTree in my life but 5 minutes was all that it took me to find the example in the documentation and do a quick spike for you. So next time you have a programming related question about some plugin or framework that you are using please put more efforts into reading the documentation first.