Adding a node to a group doesn't show in Group.memberParts

I’ve changed the pixelratio part and it seems working well also with lower zoom level. I’ve a question more, but related to association timing: when I add a node to diagram and I associate this node into a group directly, committing the operation, when I try to find all node associated to that group with

for (var mit = group.memberParts;; )

group parts is void. Why? Is there a delay between commit and effectively populate of the object model?
sequence of operation is:

  1. myDiagram.startTransaction(“addNode”);
  2. myDiagram.model.addNodeData({…}); (node is associated to a group)
  3. myDiagram.commitTransaction(“addNode”);
  4. find nodes associated to group
    what’s wrong?

That should work. Here’s what I tried. First I have a model with an empty group in it. Then I call this code:

  function test() {
    const grp = myDiagram.findNodeForKey(5);
    if (!grp) return;
    myDiagram.commit(diag => {
      diag.model.addNodeData({ text: "Epsilon", group: grp.key });
    grp.memberParts.each(p => console.log(p));
    for (let mit = grp.memberParts;; ) console.log(mit.value);

It prints 0 before the transaction and 1 after the transaction, and it correctly prints the one new member node in each of the two loops.

ehm I don’t know where’s the problem. It still remains void. I put the same instructions
but also after the add and the commit the group memberparts count shows 0.

Here’s the code:

				var grp = myDiagram.findNodeForKey(containerkey);
				importacampiparametro(idP, containerkey, "Input", pnt);

where in “importaparametro” there’s:

myDiagram.model.addNodeData({"key":parametro, "category":type, "group":group, "name":dime2, "fields":dime1, loc:point});

the “importaparametro” function is in an ajax call…maybe the transaction is not synchronized?

By “in an ajax call”, do you mean in the success or failure handler? Yes, that’s definitely asynchronous, being called long after the code that initiated the XmlHttpRequest or fetch call.

Ok probably the problem is in that asynchronous mode… well I use the ajax call just to import some data from db, and after I’ve received needed info I build the addNodeData… But what is not very clear for me is why the group object is not containing data part after the add. The object is processed in the same browser despite the call is in an ajax call…And group is already in canvas. When I see the textbox containing model data after the addnode I can’t see node but only the group. There’s some conceptual data that I’m missing

Is the value of group in your call to addNodeData the key of the Group that you want to add that node to?

If it’s wrong, that would explain the problem.

Yes, I followed all operations in debug mode with Firefox.

I’ve already use this feature in another application, that is in production environment

I’ve given you everything I can from the information that you provided.

I can suggest that you try to reproduce the problem in a simple example. That might force you to think about the differences between what you think you are doing and what you are actually doing.

of course yes, thank you. I’ve just seen that firefox console msgs start both before the ajax call and not one before and one after…probably there’s a strange behaviour linked to the ajax call, like a delay that cache updates to the model.

Resolved. I’ve brought all code regarding nodes and groups within ajax function. Obviously it was a problem of asyncronicity of the ajax function. The strange is why I didn’t get, at this point, this normal behaviour in the other application…God only knows! :-)