Code Monkey home page Code Monkey logo

Comments (4)

mar10 avatar mar10 commented on June 11, 2024

Are you sending key data with the server's JSON response? In this case FT will not generate dummy keys, so counter is not incremented.
If you leave the key data undefined, I would assume that the counter is incremented.
However: why are you getting duplicate keys? I can only think this can happen if you send keys, that have the same pattern (_ + NUMBER)

Please explain a bit more.

from fancytree.

csname1910 avatar csname1910 commented on June 11, 2024

My program allows to edit the tree.
Every time the tree is changed, it is saved as JSON to the server.
When the program is restarted later, the tree gets restored by loading the JSON from an URL from the server.

Save goes like this:
var tree: Fancytree.Fancytree = $.ui.fancytree.getTree("#tree");
var mytree = tree.toDict(true);
if (!mytree.children) mytree.children = []; // This is necessary if tree is empty, otherwise there is an error loading the tree later
var treeData: string = JSON.stringify(mytree);
// now treeData is sent to the server for later reload

Load goes from URL like shown in my post.

The keys are restored from the server, but _nextNodeKey is not set.
So if the user adds a new node, there are duplicate keys.

from fancytree.

mar10 avatar mar10 commented on June 11, 2024

Temporary keys aren't meant to be persisted, for the above reasons.
Alternatives could be to generate real keys server-side (if you need keys), or just don't send them at all (if you don't need keys in your data model).

from fancytree.

csname1910 avatar csname1910 commented on June 11, 2024

Ok, thanks! But I think it would be good if there were functions to easily just save and later reload a tree to the exact same state, without having to delete or recreate keys.
And without having to add an empty children array when the tree is empty.

from fancytree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.