开发者

How to create, rename, delete and move nodes without context menu

开发者 https://www.devze.com 2023-01-15 21:48 出处:网络
I needed a dynamic context menu for my jstree so created my own but开发者_运维问答 I still need the create, rename, delete and move functions. I had them working in the built in context menu, but can\

I needed a dynamic context menu for my jstree so created my own but开发者_运维问答 I still need the create, rename, delete and move functions. I had them working in the built in context menu, but can't seem to figure out how to do them manually.

Anyone know how?


Have a look at the crrm documentation

You may also need to apply bindings if you wish to do things after you add/edit/remove.

Writing out a full spec of each binding and its needs could take pages, so it would be best if you made your way here and search what you need - it's very helpful.

Beware - JSTree versions lower than 1.0 are very different to version 1.0+


//Create
function CreateChildNode() {

    var sel = $("#demo1").jstree("get_selected");
    $("#demo1").jstree("create", sel, "inside", { attr: { rel: "Decision" } });       
}

function AddSibling() {
        var sel = $("#demo1").jstree("get_selected");
        $("#demo1").jstree("create", sel, "after", { attr: { rel: "Decision" } });
    }

function MoveUp() {
    var sel = $("#demo1").jstree("get_selected");
    var prev = sel.prev();
    if (prev.length) {
        $("#demo1").jstree("move_node", sel, prev, "before");
    }

    /*
    var inst = $.jstree._focused(),
    slct = inst.get_selected().eq(0),
    prev = slct.prev();
    if (prev.length) inst.move_node(slct, prev, 'before');
    */
}

function MoveDown() {
    var sel = $("#demo1").jstree("get_selected");
    var next = sel.next();
    if (next.length) {
        $("#demo1").jstree("move_node", sel, next, "after");
    }
}

function Remove() {
    var sel = $("#demo1").jstree("get_selected");
    $("#demo1").jstree("remove", sel);
}


function Rename() {
    var sel = $("#demo1").jstree("get_selected");
    $("#demo1").jstree("remove", sel);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消