简体   繁体   English

Google Apps脚本-动态添加删除UiApp表单元素

[英]Google Apps Script - Dynamically Add Remove UiApp Form Elements

I am looking to create a Ui form section in my application that will Dynamically Add Remove UiApp Form Elements. 我想在我的应用程序中创建一个Ui表单部分,该部分将动态添加删除UiApp表单元素。 I was trying to use the example from App Script Tutorials here 我试图用从应用程序脚本教程的例子在这里

This example works great as far as performing the add remove elements, but when I use the submit button to capture the values, it submits as a JSON.stringify format. 这个示例在执行add remove元素方面效果很好,但是当我使用JSON.stringify按钮捕获值时,它以JSON.stringify格式提交。 When I just want to capture the values only in a text or string format that will be added to a html email. 当我只想捕获将添加到html电子邮件中的文本或字符串格式的值时。

If there is way to convert JSON.stringify to text, string or get the values only in format, I will continue to use this example. 如果有办法将JSON.stringify转换为文本,字符串或仅以格式获取值,我将继续使用此示例。

If not I was wonder if the following Javascript HTML code can be convert into GAS code and able to capture the values for each entry in a HTML email template to using in MailApp . 如果不是,我想知道以下Javascript HTML代码是否可以转换为GAS代码,并且能够捕获HTML电子邮件模板中每个条目的值以在MailApp使用。

http://jsfiddle.net/g59K7/ http://jsfiddle.net/g59K7/

Any suggestions, examples or adjustments to the codes would be greatly appreciated. 任何建议,示例或对代码的调整将不胜感激。

Thank you in advance 先感谢您

If you don't want the result to be in a JSON object, then you can adjust the _processSubmittedData(e) function. 如果您不希望结果位于JSON对象中,则可以调整_processSubmittedData(e)函数。 Right now he has it writing everything to an Object, which is fine. 现在,他可以将所有内容写入对象,这很好。 All you have to do is have a way to parse it: 您要做的就是解析它:

  function _processSubmittedData(e){
  var result = {};
  result.groupName = e.parameter.groupName;
  var numMembers = parseInt(e.parameter.table_tag);
  result.members = []; 
  //Member info array
  for(var i=1; i<=numMembers; i++){
        var member = {};
        member.firstName = e.parameter['fName'+i];
        member.lastName = e.parameter['lName'+i];
        member.dateOfBirth = e.parameter['dob'+i];
        member.note = e.parameter['note'+i];
        result.members.push(member);
  }

  var htmlBody = 'Group Name: ' + result.groupName;
  for(var a in result.members) {
    var member = result.members[a];
    var date = member.dateOfBirth;
    var last = member.lastName;
    var first = member.firstName;
    var note = member.note;

    htmlBody += first + ' ' + last + ' was born on ' + date + ' and has this note: ' + note;
  }

  MailApp.sendEmail('fakeEmail@fake.com',"Test Subject Line", "", {htmlBody: htmlBody});
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM