JSTREE jstree 使用API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSTREE jstree 使用API相关的知识,希望对你有一定的参考价值。
jstree 使用API beforechange: function() { log("About to change"); return true }, beforeopen : function() { log("About to open"); return true }, beforeclose : function() { log("About to close"); return true }, beforemove : function() { log("About to move"); return true }, beforecreate: function() { log("About to create"); return true }, beforerename: function() { log("About to rename"); return true }, beforedelete: function() { log("About to delete"); return true }, onselect : function() { log("Select"); }, ondeselect : function() { log("Deselect"); }, onchange : function() { log("Focus changed"); }, onrename : function() { log("Rename"); }, onmove : function() { log("Move"); }, oncopy : function() { log("Copy"); }, oncreate : function() { log("Create"); }, ondelete : function() { log("Delete"); }, onopen : function() { log("Open"); }, onopen_all : function() { log("Open ALL"); }, onclose : function() { log("Close"); }, error : function() { }, ondblclk : function() { log("Doubleclick"); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE); }, onrgtclk : function() { log("Rightclick"); }, onload : function() { log("Tree loaded"); }, onfocus : function() { log("Tree got focus"); }, ondrop : function() { log("Foreign node dropped"); } $("#Organizediv").jstree({ "plugins": ["thems", "html_data", "ui", "crrm", "cookies", "dnd", "search", "types", "hotkeys", "contextmenu"], "types": { "types": { "department": { "valid_children": ["department", "root"], "icon": { "image": "/Images/report_user.png" } }, "root": { "valid_children": ["department", "root"], "icon": { "image": "/Images/skysolar_logo.png" }, "remove": false } } } }) .bind("select_node.jstree", function (event, data) { if (data.rslt.obj.attr("id") != undefined) { var Url = window.location.href.toLowerCase(); var id = data.rslt.obj.attr("id").toString(); } }) //createnode .bind("create.jstree", function (e, data) { var createdata = "{"; createdata += ‘"organizeName":"‘ + data.rslt.name + ‘"‘; createdata += ‘,"parentID":‘ + parseInt(data.rslt.parent.attr("id").replace("li_", "")); createdata += "}"; $.ajax({ type: "post", url: "/WCF/UserService.svc/AddOrganization", contentType: "text/json;charset=utf-8", data: createdata, success: function (data1) { var id = parseInt(data1.d); $(data.rslt.obj).attr("id", "li_" + data1.d); }, error: function () { alert("Create Failure."); $.jstree.rollback(data.rlbk); } }) })//remove node .bind("remove.jstree", function (e, data) { data.rslt.obj.each(function () { var removedata = ‘{"ids":‘ + this.id.replace("li_", "") + ‘}‘; $.ajax({ type: "post", url: "/WCF/UserService.svc/DeleteOrganize", contentType: "text/json;charset=utf-8", data: removedata, success: function (r) { alert(r.d); if (r.d != "Delete Success") { $.jstree.rollback(data.rlbk); } }, error: function () { alert("Remove Failure."); $.jstree.rollback(data.rlbk); } }); }); }) //rename .bind("rename.jstree", function (e, data) { var id = parseInt(data.rslt.obj.attr("id").replace("li_", "")); var newName = data.rslt.new_name; if (newName != "" && newName != undefined) { var renamedata = ‘{"id":‘ + id + ‘,"newName":"‘ + newName + ‘"}‘; $.ajax({ type: "post", url: "/WCF/UserService.svc/RenameOrganization", contentType: "text/json;charset=utf-8", data: renamedata, success: function (r) { }, error: function () { $.jstree.rollback(data.rlbk); } }); } }) //move .bind("move_node.jstree", function (e, data) { data.rslt.o.each(function (i) { var id = parseInt(this.id.replace("li_", "")); var newparentid = 0; if (data.rslt.np.attr("id") != "Organizediv") { newparentid = parseInt(data.rslt.np.attr("id").replace("li_", "")); } var index = parseInt($("#" + this.id).parent().children().index($("#" + this.id))); var movedata = ‘{‘ + ‘"id":‘ + id + ‘,"newParentId":‘ + newparentid + ‘,"index":‘ + index + ‘}‘; $.ajax({ type: "post", url: "/WCF/UserService.svc/SortOrganize", contentType: "text/json;charset=utf-8", data: movedata, success: function (r) { }, error: function () { alert("Move Failure."); $.jstree.rollback(data.rlbk); } }); }); });
以上是关于JSTREE jstree 使用API的主要内容,如果未能解决你的问题,请参考以下文章