设置文本区域的文本属性不正常

时间:2016-09-22 01:33:48

标签: javascript google-apps-script

请告诉我我做错了什么。基本上,我想要的是将结果放在" textarea"中阅读电子邮件。为了测试我是否真的能够为我的" textarea"设置任何内容,我尝试" setText"一个静态字符串。请参阅以下代码。

function showSidebar2(){
  var app = UiApp.createApplication().setTitle('An improved GUI').setWidth(300);

      var servHandler = app.createServerHandler("myServerHandler");

      var grid = app.createGrid(3,2);
      grid.setWidget(0,0,app.createLabel("Unread Messages: "));
      grid.setWidget(0,1,app.createLabel("").setId("server-response"));
      grid.setWidget(1,0,app.createButton("Check Messages").addClickHandler(servHandler));
      grid.setWidget(2,0, app.createTextArea().setId("server-messages").setName("server-messages"));

      //var mybutton = app.createButton('Check Messages');
      var mypanel = app.createVerticalPanel();
      mypanel.add(grid);
      //mypanel.add(mybutton);
      app.add(mypanel);

      checkMessages();
      SpreadsheetApp.getUi().showSidebar(app);   
}

function myServerHandler(e) {
  //Logger.log(JSON.stringify(e, undefined, 2));

  var app = UiApp.getActiveApplication();
  app.getElementById("server-messages").setText("Loading messages....")
  var threads = GmailApp.getInboxThreads(0, 10);
  for(var i=0; i<threads.length; i++){
    var messages = threads[i].getMessages();
    if(messages[0].isUnread()){
      Logger.log(messages[messages.length-1].getSubject());
      Logger.log(messages[messages.length-1].getPlainBody());
    }
    Utilities.sleep(1000);
  }
}

使用此代码,我可以在日志中看到电子邮件结果,但我无法在&#34; textarea&#中设置静态文本正在加载消息.... 34 ;.该怎么做?请告诉我,如果可能的话,如何替换文本正在加载消息.... ,结果我从阅读电子邮件到#34; textarea&#34;。谢谢。

1 个答案:

答案 0 :(得分:-1)

来自https://developers.google.com/apps-script/reference/ui/

Deprecated. The UI service was deprecated on December 11, 2014. To create user interfaces, use the HTML service instead.

(文字版)

  

已过时。 UI服务是deprecated on December 11, 2014。   要创建用户界面,请改用HTML service