Vis.js JSON数据到Google Spreadsheets范围

问题描述 投票:2回答:1

我尝试从Vis.js (here a example!)节点的位置和与ID相关的边缘检索数据到Google SpreadSheets范围时遇到了一个小问题。

这是代码(HTML和GAS)

let nodeArray = []

data.forEach(element => {
  let obj = {}
  obj.id = element[0]
  obj.label = element[1]
  obj.title = element[2]
  obj.group = element[3]
  obj.x = element[4]
  obj.y = element[5]

  nodeArray.push(obj)
  return element
})
//Logger.log(nodeArray);
return nodeArray;
}

function lineArray() {

  const data = ss.getSheetByName("Conecciones").getRange(2, 1, ss.getLastRow() - 1, 5).getValues();

  let edgArray = []

  data.forEach(element => {
    let obj = {}
    obj.from = element[0]
    obj.label = element[2]
    obj.dashes = element[3]
    obj.to = element[4]
    edgArray.push(obj)
    return element
  })
  //Logger.log(edgArray);
  return edgArray;
}
<html>

<head>
  <script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>


</head>

<body>

  <div id="mynetwork"></div>
  <input type="button" id="export_button" onclick="exportNetwork()" value="export">
  <p id="input_output" style="height: 680px;"></p>

  <script type="text/javascript">
    function init() {

      container = document.getElementById('mynetwork');
      exportArea = document.getElementById('input_output');
      network = google.script.run.withSuccessHandler(([nodes, edges]) => new vis.Network(container, {
        nodes: nodes,
        edges: edges
      }, options)).sample();

    };

    function addConnections(elem, index) {
      elem.connections = network.getConnectedNodes(index);
    }

    function exportNetwork() {
      var nodes = objectToArray(network.getPositions());
      nodes.forEach(addConnections);
      var exportValue = JSON.stringify(nodes, undefined, 2);
      exportArea.innerHTML = exportValue;
    }

    function objectToArray(obj) {
      return Object.keys(obj).map(function(key) {
        obj[key].id = key;
        return obj[key];
      });
    }

    init();
  </script>
</body>

</html>

我认为问题出在这里,在HTML方面🡇

function addConnections(elem, index) {                                                                          
    elem.connections = network.getConnectedNodes(index);
  }

  function exportNetwork() {
    var nodes = objectToArray(network.getPositions());
    nodes.forEach(addConnections);
    var exportValue = JSON.stringify(nodes, undefined, 2);
    exportArea.innerHTML = exportValue;
  }

  function objectToArray(obj) {
    return Object.keys(obj).map(function (key) {
    obj[key].id = key;
    return obj[key];
    });
  }

摘要:

在这一点上,我在从Google脚本端读取数据时遇到了问题(其100%经过测试,它可以在没有“假定的问题部分”的情况下工作)]]

之前,非常感谢!

我在尝试从Vis.js(这里是一个示例!)节点的位置和与ID相关的边缘到Google SpreadSheets范围中检索数据时遇到了一个小问题。这是代码(HTML和GAS)...

javascript html google-apps-script google-sheets-api vis.js
1个回答
2
投票

此修改如何?请认为这只是几个可能的答案之一。


推荐问答