This is a migrated thread and some comments may be shown as answers.

Obtain/Determine data represented after appends and other drag and drops

2 Answers 72 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 29 Mar 2012, 07:12 PM
Consider a tree built by drag and drop.  Dropped nodes are added to the tree.  Then the user uses tree drag and drop to rearrange and/or change level of the tree nodes.

How would I obtain the 'data' the that the treeview is currently presenting ?

Thanks,
Richard

2 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 30 Mar 2012, 09:08 AM
After a bit of knocking about in the TreeView source, I think the following will deliver the data being show in the treeview
    function treeToData (tree) {
        var items = [];
        var $items = tree.find('> .k-item');
        $items.each( function(index,item) {
            items.push (itemToData (item));
        });
        return items;
    }
    function itemToData(item) {
        var text = $(item).find('> div > span.k-in').text();
        var group = {
            text: text,
            items: treeToData ($(item).find('> .k-group'))
        };
        return group;
    }
 
var treedata = treeToData ($('#var-tree1'));alert(JSON.stringify(treedata));

0
King Wilder
Top achievements
Rank 2
answered on 27 Apr 2012, 07:39 PM
Richard,

Thanks for this.  I've been needing to implement this precise functionality.  I'll give your functions a try.

Thanks,

King Wilder
Tags
TreeView
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
King Wilder
Top achievements
Rank 2
Share this question
or