在 create.jstree 上的 .bind 中,我的 $.ajax 调用中的一切似乎都是正确的。但是,由于某种原因,对控制器的调用(我使用的是 MVC 3)没有发生。我在 ajax 调用引用的 POST 函数上放置了一个断点,但它甚至从未被调用过。这使我相信 bind 和 ajax 调用的组合存在问题,导致 post 函数无法被调用。我会很感激你的建议。
jstree代码:
$("#RequirementsTree")
.bind("select_node.jstree", function(event, data) {
if(is_requirement_node(data))
{
var id = data.rslt.obj.attr("id");
if(id != null)
{
$("#RequirementsTree").jstree('close_all')
}
else {
alert("Requirement node select error");
}
}
})
.bind("create.jstree", function(e, data) {
alert(data.rslt.obj.text());
alert(ParentNode);
// Ajax call to Server with parent node id and new node text
debugger;
$.ajax({
type: "POST",
url: function(node) {
return "/RMS/insertRequirementNode";
},
data: {
ParentID : ParentNode,
ChildNodeText : data.rslt.obj.text()
},
success: function(new_data) {
return new_data;
}
});
ParentNode = null;
if (data.rslt.parent == -1) {
alert("Can not create new root directory");
// Rollback/delete the newly created node
$.jstree.rollback(data.rlbk);
return;
}
BranchReqFLag = null;
}).jstree({
json_data: {
data: RBSTreeModel,
ajax: {
type: "POST",
data: function (n) {
return {
NodeID: n.attr("id").substring(4),
Level: n.attr("name").substring(7)
};
},
url: function (node) {
return "/Audit/GetRequirementsTreeStructure";
},
success: function (new_data) {
return new_data;
}
}
},
contextmenu: {
items: function($node) {
return {
createItem : {
"label" : "Create New Branch",
"action" : function(obj) { this.create(obj); BranchReqFlag = "Branch"; ParentNode = obj.attr("id").substring(4);}
},
renameItem : {
"label" : "Rename Branch",
"action" : function(obj) { this.rename(obj);}
}
};
}
},
plugins: ["themes", "json_data", "ui", "crrm", "contextmenu"]
});
控制器 POST 功能:
[AllowAnonymous]
[HttpPost]
public int insertRequirementNode(int ParentID, string ChildNodeText)
{
RBSText CurrNode = new RBSText();
int CurrentNodeID = -1;
//CurrNode.RMSHierarchyText = ChildNodeText;
using (Contract ActiveContract = getContract())
{
try
{
// Inserts the new node beneath the Parent Node
CurrentNodeID = ActiveContract.CreateRMSNode(CurrNode, ActiveContract.ContractId, ActiveContract.user_id, 2, "Child");
}
catch (Exception ex)
{
throw ex;
}
}
return CurrentNodeID;
}