I am trying to load data asynchronously to the HTML file in the Google Script editor.
My current output is as follows:
<ul id="cats">
<?
var cat = BASIC_DATA.categories;
for(var i=2;i<cat.length;i++){
var categoryName = cat[i][0];
var categoryIcon = ICON[cat[i][0]];
var categoryNumb = cat[i][1];
?>
<li name="<?=categoryName?>" type="category"><span class="icon" style="background-position:<?=categoryIcon?>;"></span><span class="title"><?=categoryName?></span><?='('+categoryNumb+')'?></li>
<?
}
?>
</ul>
What I am trying to achieve is the following, but using the method suggested by Google here HTML Service: Best Practices
$(function() {
google.script.run.withSuccessHandler(showThings)
.getLotsOfThings();
});
function showThings(cat) {
var list = $('#cats');
var cat = BASIC_DATA.categories;
var categoryName = cat[i][0];
var categoryIcon = ICON[cat[i][0]];
var categoryNumb = cat[i][1];
list.empty();
for (var i = 0; i < cat.length; i++) {
list.append('<li name="' + categoryName + '" type="category"><span class="icon" style="background-position:' + categoryIcon + '"></span><span class="title">' + categoryName + '</span>(' + categoryNumb + ')</li>');
console.log(list);
}
}
So far my list is empty and I get errors in the console
TypeError: google.script.run.withSuccessHandler(...).getLotsOfThings is not a function
Here is my getLotsOfThings() function in Code.gs
function getLotsOfThings(){
var tabSheetCategories = SpreadsheetApp.openById(SHEET_ID).getSheetByName(CATEGORIES);
var tabSheetAbout = SpreadsheetApp.openById(SHEET_ID).getSheetByName(ABOUT_DATA);
var tabSheetHelp = SpreadsheetApp.openById(SHEET_ID).getSheetByName(HELP_DATA);
BASIC_DATA = {
"tab_about" : getValue(tabSheetAbout,"A2"),
"tab_help": getValue(tabSheetHelp,"A2"),
"categories": tabSheetCategories.getDataRange().getValues()
};
return false;
}
returnanything anywhere ingetLotsOfThings(). The returned data will be passed to the HTML-sideshowThings()function.BASIC_DATA is not definederror. I know for sure that it is defined as I can access the array with my initial code.function include(filename) { return HtmlService.createHtmlOutputFromFile(filename) .getContent(); }