[
{"id":1,"label":"Node 2"},
{"id":2,"label":"Node 3"},
{"id":3,"label":"Node 4"},
{"id":4,"label":"Node 5"}
]
Hi! In the following code, the function getArray() returns this string ↑. Do you know how to connect it with the variable nodes in the .html . I pasted the codes, Thanks!
function getArray(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = ss.getRange(1,1,ss.getLastRow()-1,2).getValues();
let objArray = []
data.forEach(element => {
let obj = {}
obj.id = element[0]
obj.label = element[1]
objArray.push(obj)
return element
}
)
var obj = JSON.stringify(objArray);
//Logger.log(obj);
return obj;
}
<!doctype html>
<html>
<head>
<title>Network</title>
</head>
<body>
<div id="mynetwork"></div>
<script type="text/javascript">
var nodes = [
{"id":1,"label":"Node 2"},
{"id":2,"label":"Node 3"},
{"id":3,"label":"Node 4"},
{"id":4,"label":"Node 5"}
];
</script>
</body>
</html>
Recap: My goal is use the returned "obj" in .gs as var "nodes" in .html. I don't know if the programming speech its correct. Thanks!
If some can share me the code, im going to thanks you a lot thanks!
var nodes = [...]togoogle.script.run.withSuccessHandler(nodes => console.log(nodes)).getArray()in HTML side? RefDoesn't work. And I cannot understand aboutuse the returned "obj" in .gs as var "nodes" in .html. Becausegoogle.script.run.withSuccessHandler(nodes => console.log(nodes)).getArray()brings the values from returned fromgetArray()to HTML side. So can you provide the detail information for replicatingDoesn't work? From this, I would like to try to understand about your goal.google.script.run.withSuccessHander(fncNameToHandleReturn).fncNameHere()and then use JavaScript and the DOM to manipulate the HTML in the browser. Do you want the content to be merged when the HTML first loads, or at some point afterwards?nodesis required to be used as an object. So I think thatreturn objArrayis used instead ofreturn objingetArray(). By this, I think thatnodesreturned bygoogle.script.run.withSuccessHandler(nodes => console.log(nodes)).getArray()can be used for your script. How about this?