The*_*ude 4 javascript events contextmenu event-handling jstree
我正在尝试使用jstree的contextmenu捕获新创建的节点的名称.我可以捕获我正在添加新节点的父节点的名称(使用obj.text()),但是,我真正需要的是新创建的节点的名称.
所以,不知何故,需要有一个"onChange"事件,可以在jstree contextmenu中调用,一旦用户点击进入新创建的节点,就会触发该事件?
有任何想法吗?我附上了contextmenu代码:
}).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); alert(obj.text())},
"_class" : "class"
},
renameItem : {
"label" : "Rename Branch",
"action" : function(obj) { this.rename(obj);}
},
deleteItem : {
"label" : "Remove Branch",
"action" : function(obj) { this.remove(obj); }
}
};
}
},
plugins: ["themes", "json_data", "ui", "crrm", "contextmenu"]
});
Run Code Online (Sandbox Code Playgroud)
您可以绑定到"create.jstree"事件,该事件将在创建节点后触发.在该事件的回调中,您将可以访问新创建的节点,并且可以根据您的选择回滚/还原创建节点操作.它的文档很缺乏,但是在演示页面上有一个例子.这是我的代码中的另一个例子:
}).jstree({... You jstree setup code...})
.bind("create.jstree", function(e, data) {
// use your dev tools to examine the data object
// It is packed with lots of useful info
// data.rslt is your new node
if (data.rslt.parent == -1) {
alert("Can not create new root directory");
// Rollback/delete the newly created node
$.jstree.rollback(data.rlbk);
return;
}
if (!FileNameIsValid(data.rslt.name)) {
alert("Invalid file name");
// Rollback/delete the newly created node
$.jstree.rollback(data.rlbk);
return;
}
.. Your code etc...
})
Run Code Online (Sandbox Code Playgroud)