码迷,mamicode.com
首页 > Windows程序 > 详细

【JSTREE】 jstree 使用API

时间:2016-12-28 01:38:46      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:als   ajax   ase   branch   user   nod   created   move   foreign   

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

标签:als   ajax   ase   branch   user   nod   created   move   foreign   

原文地址:http://www.cnblogs.com/flydkPocketMagic/p/6227717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!