admin管理员组文章数量:1426022
I want to return the object from code.gs to html file on google app script. But I couldnt return the values. I want to display the values on the html interface. I couldnt return value at "alert(retsearch[0].yourname);" Please help, Thank you!!
Code.gs
function getData() {
var ss=SpreadsheetApp.openById('1PWJyASHmjJ_W8-72u8bbrGbN-Nv6kdkCvjdmYuNNlEY');
var sheet=ss.getSheetByName('invoice1');
return sheet;
}
function processSearch(searchform){
var sheet = getData();
var data = ObjApp.rangeToObjects(sheet.getDataRange().getValues());
var searchfname=searchform.surname;
var searchcname=searchform.scustomername;
var searchpayementdate=searchform.spayementdate;
var results = [];
for(var i=0 ; i < data.length ; i++) {
if(searchfname == data[i].yourname || searchcname == data[i].customername || searchpayementdate == data[i].paymentday ) {
var events ={yourname:data[i].yourname, customername:data[i].customername,paymentday:data[i].paymentday };
results.push(events);
}
}
Logger.log(results);
return results;
}
Html file
<form id="fsrecord">
<input type="text" name="surname" id="surname" placeholder="by your name"/> <br/>
<input type="text" name="scustomername" id="scustomername" placeholder="by customer name"/> <br/>
<input type="date" name="spayementdate" id="spayementdate" placeholder="by payment date"> <br>
<input type="submit" value="search" />
</form>
<script>
$( document ).ready(function() {
$("#fsrecord").submit(function() {
google.script.run.withSuccessHandler(function(retsearch){
alert(retsearch[0].yourname);
}).processSearch(this);
});
});
</script>
I want to return the object from code.gs to html file on google app script. But I couldnt return the values. I want to display the values on the html interface. I couldnt return value at "alert(retsearch[0].yourname);" Please help, Thank you!!
Code.gs
function getData() {
var ss=SpreadsheetApp.openById('1PWJyASHmjJ_W8-72u8bbrGbN-Nv6kdkCvjdmYuNNlEY');
var sheet=ss.getSheetByName('invoice1');
return sheet;
}
function processSearch(searchform){
var sheet = getData();
var data = ObjApp.rangeToObjects(sheet.getDataRange().getValues());
var searchfname=searchform.surname;
var searchcname=searchform.scustomername;
var searchpayementdate=searchform.spayementdate;
var results = [];
for(var i=0 ; i < data.length ; i++) {
if(searchfname == data[i].yourname || searchcname == data[i].customername || searchpayementdate == data[i].paymentday ) {
var events ={yourname:data[i].yourname, customername:data[i].customername,paymentday:data[i].paymentday };
results.push(events);
}
}
Logger.log(results);
return results;
}
Html file
<form id="fsrecord">
<input type="text" name="surname" id="surname" placeholder="by your name"/> <br/>
<input type="text" name="scustomername" id="scustomername" placeholder="by customer name"/> <br/>
<input type="date" name="spayementdate" id="spayementdate" placeholder="by payment date"> <br>
<input type="submit" value="search" />
</form>
<script>
$( document ).ready(function() {
$("#fsrecord").submit(function() {
google.script.run.withSuccessHandler(function(retsearch){
alert(retsearch[0].yourname);
}).processSearch(this);
});
});
</script>
Share
Improve this question
asked Mar 2, 2017 at 11:13
JonaJona
4062 gold badges8 silver badges22 bronze badges
1 Answer
Reset to default 4You can convert the stringify the data at the server side and parse the JSON at the client side.
code.js
function processSearch(searchform){
...
...
return JSON.stringify(results);
}
index.html
$(document).ready(function () {
$("#fsrecord").submit(function () {
google.script.run.withSuccessHandler(function (retsearch) {
var response = JSON.parse(retsearch);
alert(response[0].yourname);
}).processSearch(this);
});
});
本文标签: javascriptHow to return object in google app scriptStack Overflow
版权声明:本文标题:javascript - How to return object in google app script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745461312a2659336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论