Insert multiple nodes at once

518 views
Skip to first unread message

Kārlis Bērziņš

unread,
Jul 18, 2014, 7:25:29 AM7/18/14
to jst...@googlegroups.com
I got tree like this. This is placed in event from plupload - "FileUploaded"
var data = info.response;
var obj = jQuery.parseJSON( data );

jQuery
('.uploader-tree').jstree(
       
{ 'core' : {
           
"check_callback" : true,
           
'data' : obj
       
},
           
"plugins" : [ "dnd", "state", "types", "crrm" ]
       
}
   
)

Inserting new node with that (in single file upload)

var tree = jQuery(".uploader-tree");
tree
.jstree(true).create_node(tree, info);

Q: How can i insert multiple nodes at once from json obj ? I am using zip file upload and i need to show extracted files. And tree must be already created because of single file upload.

It would be nice, if it is possible with docs given sample
'data' : [ 'Simple root node', { 'text' : 'Root node 2', 'state' : { 'opened' : true, 'selected' : true }, 'children' : [ { 'text' : 'Child 1' }, 'Child 2' ] } ]

Ivan Bozhanov

unread,
Jul 18, 2014, 8:02:37 AM7/18/14
to jst...@googlegroups.com
Doesn't this work:
jQuery('.uploader-tree').jstree(true).create_node(tree, { text : 'Test', children : ['Child 1',' Child 2'] });

Best regards,
Ivan

Kārlis Bērziņš

unread,
Jul 18, 2014, 8:18:50 AM7/18/14
to jst...@googlegroups.com
Thanks for fast response. Yes, it works good for me. But is it possible to add nodes like this?
.create_node(tree, ["Root1",  "Root2"]);

Or in this case i need call create_node 2 times.

Thanks.

Ivan Bozhanov

unread,
Jul 20, 2014, 1:52:16 PM7/20/14
to jst...@googlegroups.com
Currently you will have to call it twice, I will see if I can improve this in the future.

Best regards,
Ivan
Message has been deleted

Sakshi Gupta

unread,
Jul 21, 2015, 10:05:32 AM7/21/15
to jst...@googlegroups.com

Hi Ivan,

My requirement is also something similar to the above problem. I want to create two sub-nodes along with the parent node on clicking the 'create' of the context menu.
For example, i want my tree something like below:-
       
                         Rule Category (node already present)
                             -- Rule Id   (child of rule category)
                                 - rule id one (first child of Rule id)
                                 - rule id two  (second child of Rule id)
                                 
        now what I want is that when i right click on the 'Rule Category', and click on 'create' , 'Rule id' node gets created along with the 'rule id one' and 'rule id two' nodes instantly.
       
What I tried to do is I tried to modified the "action" of the 'create' as below, but not achieved what I wanted.

                          "create Rule" : {
                        "separator_before"    : false,
                        "separator_after"    : false,
                        "_disabled"            : false, //(this.check("create_node", data.reference, {}, "last")),
                        "label"                : "Create Rule",
                        "action"            : function (data) {
                            var inst = $.jstree.reference(data.reference),
                                obj = inst.get_node(data.reference);
                            inst.create_node(obj, {}, "last", function (new_node) {
                                setTimeout(function () { inst.edit(new_node); },0);
                             }
                            );
                           
                            //for socond node
                            var inst1 = $.jstree.reference(data.reference),
                            obj1 = inst1.get_node(data.reference);
                            inst1.create_node(obj1, {}, "last", function (new_node) {
                                setTimeout(function () { inst1.edit(new_node); },0);
                              
                             }
                            );
                        }
                    },

Please provide the solution for this.

Thanks
Sakshi

Ivan Bozhanov

unread,
Jul 21, 2015, 10:15:18 AM7/21/15
to jst...@googlegroups.com, sakshig...@gmail.com
Just read the accepted solution.

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages