Closed blavv closed 6 months ago
We have created this example: https://code.balkan.app/family-tree-js/change-id-on-update#JS
Hi @ZornitsaPesheva. This example you provide only shows how to override the generateID()
. What @blavv is asking if it's possible to "replace" an existing node's id, and to propagate this id replacement to other nodes (i.e. updating partnerIds
, fid
, mid
, etc...)?
My use case is similar to @blavv.
Bob Smith
in FamilyTreeJS, and its id is autogenerated to be _abc
123
to the node John Smith
{
"ids": {
"_abc": "123"
}
}
Bob Smith
in FamilyTreeJS by changing its id from _abc
to 123
There are two options:
Option 1. Use the finish argument from the latest version
family.onUpdateNode(function(args, finish){
fetch('https://mydomain.com/generateId')
.then(response => response.json())
.then(id => {
args.addNodesData[0].id = id;
fetch('https://mydomain.com/update'); //post data from args
finish();
});
return false;
});
Option 2. Update the server and return new ids, then updated the client side nodes
family.onUpdateNode(function(args){
var that = this;
fetch('https://mydomain.com/update')//post data from args
.then(response => response.json())// return old id new id collection
.then(old_new_ids => {
for (var oldId in old_new_ids){
that._get(oldId).id = old_new_ids[oldId];
}
that.draw();
});
});
We have removed the "finish" parameter from the previous post
Created Server side code to demonstrate how to update the ids from auto generated ids on the server side
https://github.com/plamen-peshev/FamilyTreeJSGenerateNewNodesIdsFromServerSide
Is it possible to assign a new ID to a node that's already rendered on the family tree?
For instance, if "Bob" node has ID "_abc", I want to replace it with "12345" (generated on the backend server AFTER the node was created on the tree). Overriding generateID() doesn't work in my case.