开发者

EXTJS: treepanel move a branch programmatically

开发者 https://www.devze.com 2023-01-08 06:24 出处:网络
I have a tree where users can drag and drop branches. Now this works all well and good, but I need to be able to move a branch programmatically.

I have a tree where users can drag and drop branches.

Now this works all well and good, but I need to be able to move a branch programmatically.

I need to simulate a cut and paste (I will have the user using buttons instead of Ctrl- X and V).

Does anyone have an idea of whe开发者_开发问答re I should start?


Ok, i found the solution and it ended up being really, REALLY simple:

var child = tree.getSelectionModel().getSelectedNodes();
var parent = tree.getNodeById('ABC123');
parent.appendChild(child);

it will even automagically remove the node from its original spot and it even moves any children of the node moved.

Note that this will only work on one node at the moment (even though it is using selectedNodes) i will post something more substantial later.


Here is a cut and paste that will work for multiple nodes at one time. This version will also hide any nodes that have been "cut" and won't show them again till they get pasted. during the paste it will only use the first node selected, all others will just be ignored.

var Children = new Array();

function CutChildren(){
    Children = tree.getSelectionModel().getSelectedNodes();
    var limit = Children.length;
    for (count =0; count < limit; count++){
        Children[count].getUI().hide();
    }

}

function PasteChildren(){
    var selected = new Array();
    selected = tree.getSelectionModel().getSelectedNodes();
    var limit = Children.length;
    for (count =0; count < limit; count++){
        selected[0].appendChild(Children[count]);
        Children[count].getUI().show();
        if (count > 100){
        break;}
    }

}


I have never played with that method so I can't really give you a full solutin, but the TreePanel class has a movenode method with the following arguments... Tree tree, Node node, Node oldParent, Node newParent, Number index

There are also events tied to this method. Hope this helps.

EDIT - I read the API too quick, those are events. I think the only way you can manually do this is by using the appendChild and removeChild methods.

0

精彩评论

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