Skip to main content

Is it possible to add multiple nodes with the addNodes event?

4 replies [Last post]
dwhite
Offline
Joined: 2008-06-16
Points: 0

Hi,

Just wondering if there is a way to use the /dojo/tree/addNodes event to add multiple child nodes in a single call.

I.e. in my tree I have a target node: NodeX, and upon expansion of this node I want to add 2 child nodes, NodeY and NodeZ. I would like to do this in a single call to the addNodes event. Is this possible?

I did try the following example code:

var nodes = [{
label : 'Node Y',
expanded : true,
children : [
{label : 'Node Y .1'},
{label : 'Node Y .2'}
]
},
{
label : 'Node Z',
expanded : true,
children : [
{label : 'Node Z .1'},
{label : 'Node Z .2'}
]
}];
jmaki.publish("/dojo/tree/addNodes", {targetId : 'NodeX', value : nodes});

But, although this code does not generate an error - it fails to add any nodes to the tree (it works fine when adding the nodes seperately).

I presume I am going to have to publish the addNodes event for each child node I want to add - but thought I would check in case there is a way to do this in a single call...

Thanks very much in advance

David

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
marcfarrow
Offline
Joined: 2008-06-19
Points: 0

does your tree/nodes subscribe to the the same? i.e. "/dojo/tree/addNodes"

dwhite
Offline
Joined: 2008-06-16
Points: 0

Thanks for the quick response. Yes the tree has the following subscribe attribute specified.

subscribe="['/dojo/tree']"

It works perfectly when there is a single 'top level' node to add (it adds that node's children ok as well), Its only when I specify a JSON Array of 'top level' nodes in the payload that it fails.

marcfarrow
Offline
Joined: 2008-06-19
Points: 0

I dont think you need the "[","]"

try subscribe="/dojo/tree"

dwhite
Offline
Joined: 2008-06-16
Points: 0

I have added a for loop in my glue file to loop the JSON array of nodes, each node is added with a seperate call to publish the addNodes event, it works fine:

//nodes has been set to a JSON Array of node objects

for (var key = 0; (key < nodes.length); key++) {
jmaki.publish("/dojo/tree/addNodes", {targetId : nodeId, value : nodes[key]});
}

Thanks for your guidance