Created
February 18, 2018 04:52
-
-
Save CJOWood/36a16d127e026012fea5eb68c8280d2c to your computer and use it in GitHub Desktop.
Using withSuccessHandler to Return Array and Make List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
FormApp.getUi() // Or DocumentApp or FormApp. | |
.createMenu('Custom Menu') | |
.addItem('Show sidebar', 'showSidebar') | |
.addToUi(); | |
} | |
function showSidebar() { | |
Logger.log("Showing Sidebar..."); | |
var html = HtmlService.createHtmlOutputFromFile('test') | |
.setTitle('My custom sidebar') | |
.setWidth(300); | |
FormApp.getUi() // Or DocumentApp or FormApp. | |
.showSidebar(html); | |
} | |
function getSomeData() { | |
return [["Cell 1"],["Cell 2"],["Cell 3"],["Cell 4"],["Cell 5"]]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<script> | |
google.script.run.withSuccessHandler(onSuccess) | |
.getSomeData(); | |
function onSuccess(data) { | |
var div = document.getElementById('output'); | |
var list = document.createElement('ul'); // Create a <li> node | |
for(var i = 0; i < data.length; i++){ | |
var item = document.createElement('li'); | |
item.appendChild(document.createTextNode(data[i])); | |
list.appendChild(item); | |
} | |
div.appendChild(list); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="output"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment