Google Script PropertiesService以不可读的格式存储数据

时间:2015-04-29 16:05:03

标签: google-apps-script web-storage

我正在尝试使用PropertiesService来存储数据,以便下次加载应用时每个用户的设置都会显示。我也在使用这些属性来构建和运行触发器。问题是,当我尝试从设置它们的函数之后的函数调用userProperties时,该数组显示为Ljava.lang.Object而不是实际值。我用JSON尝试了一些东西,但无济于事。

Form.html

<?!= include('Style'); ?>

<div id="formDiv">
    <form id="myForm">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th scope="col">
                        <h3 span style="font-family:arial,helvetica,sans-serif;">Select</span></th>
                    <th scope="col">
                        <h3 span style="font-family:arial,helvetica,sans-serif;">Label</span></th>
                    <th scope="col">
                        <h3 span style="font-family:arial,helvetica,sans-serif;">Drive target</span></th>
                </tr>
            </thead>
            <tbody>
                <? var label = GmailApp.getUserLabels();
                   for (i = 0; i < label.length; i++) { ?>    
                <tr>
                    <td style="text-align: center;">
                        <span style="font-family:arial,helvetica,sans-serif;"><input id="index" type="checkbox" name="index" value="<?= [i]; ?>"  /></span></td>
                    <td>
                        <span style="font-family:arial,helvetica,sans-serif;"><input id="label" type="text" style="border:none" size="60" name="label" value="<?= label[i].getName(); ?>" readonly /></span></td>
                    <td>
                        <span style="font-family:arial,helvetica,sans-serif;">Gmail Backup/<input id="target" type="text" size="60" maxlength="128" name="target" value="<?= label[i].getName(); ?>" /></span></td>
                </tr>                
                <? } ?>
            </tbody>
        </table>
        <p><input type="submit" value="Test" onclick="google.script.run.setProperties(this.parentNode.parentNode)" />   
        <input type="submit" value="Save" onclick="google.script.run.createTrigger(); google.script.run.thanks()" />   
        </p>
    </form>
</div>

<?!= include('JavaScript'); ?>

Code.gs

function doGet() {
  var form = HtmlService.createTemplateFromFile("Form")
  .evaluate()
  .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  return form;
}

function setProperties(form) {
  var userProperties = PropertiesService.getUserProperties();
  var formProperties = userProperties.setProperty("FORM", form);
  propTest();
}

function propTest() {
  var userProperties = PropertiesService.getUserProperties();
  var filledForm = userProperties.getProperty("FORM");
  Logger.log(filledForm);
}

执行记录

[15-04-29 09:54:09:912 MDT] Starting execution
[15-04-29 09:54:09:932 MDT] PropertiesService.getUserProperties() [0 seconds]
[15-04-29 09:54:10:032 MDT] (class).setProperty([FORM, {index=[3, 4], target=[Test 01-A, Test 01-A/Test 01-B, Test 01-A/Test 01-B/Test 01-C, Test 01-A/Test 01-B/Test 01-C/Test 01-D, Test 01-A/Test 01-B/Test 01-C/Test 01-D/Test 01-E, Test 02 - A (+_!@#$%&*), Test 02 - A (+_!@#$%&*)/Test 02 - B (+_!@#$%&*), Test 02 - A (+_!@#$%&*)/Test 02 - B (+_!@#$%&*)/Test 02 - C (+_!@#$%&*)], label=[Test 01-A, Test 01-A/Test 01-B, Test 01-A/Test 01-B/Test 01-C, Test 01-A/Test 01-B/Test 01-C/Test 01-D, Test 01-A/Test 01-B/Test 01-C/Test 01-D/Test 01-E, Test 02 - A (+_!@#$%&*), Test 02 - A (+_!@#$%&*)/Test 02 - B (+_!@#$%&*), Test 02 - A (+_!@#$%&*)/Test 02 - B (+_!@#$%&*)/Test 02 - C (+_!@#$%&*)]}]) [0.098 seconds]
[15-04-29 09:54:10:032 MDT] PropertiesService.getUserProperties() [0 seconds]
[15-04-29 09:54:10:065 MDT] (class).getProperty([FORM]) [0.031 seconds]
[15-04-29 09:54:10:065 MDT] Logger.log([{index=[Ljava.lang.Object;@6cb426d, target=[Ljava.lang.Object;@a760597, label=[Ljava.lang.Object;@4a6901de}, []]) [0 seconds]
[15-04-29 09:54:10:066 MDT] Execution succeeded [0.133 seconds total runtime]

0 个答案:

没有答案