Skip to content

Save data Tree  #104

@Armedrok

Description

@Armedrok

I need to save the whole structure of the Tree.
I had some difficult so I choice to save in Firebase 4 field (id, pid, isleaf, name) but as conseguence I need a function to rebuild the Tree.
I would like to know if there is a more easy mode to Save and Reload the Tree (when I try to use "stringifiy" I obtain a circular reference). Thanks in advance, every information will really very appreciated

Could you send me some information

saveScopeCompany() {
var vm = this;
function _dfs(oldNode) {
var newNode = {};

    for (var k in oldNode) {
      if (k !== "children" && k !== "parent") {
        newNode[k] = oldNode[k];
      }
    }
    if (oldNode.children && oldNode.children.length > 0) {
      newNode.children = [];

      for (var i = 0, len = oldNode.children.length; i < len; i++) {
        newNode.children.push(_dfs(oldNode.children[i]));
         fetch("https://smart-icon-a8b9f-default-rtdb.firebaseio.com/treescopes.json",
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify({
              id: oldNode.children[i]["id"],
              pid: oldNode.children[i]["pid"],
              isLeaf: oldNode.children[i]["isLeaf"],
              name: oldNode.children[i]["name"],
            }),
          }
        );
      }
    }
  }
  vm.newTree = _dfs(vm.data);
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions