UI获取价值函数在文档应用程序无法正常工作(UI get value function not wo

2019-10-30 09:46发布

貌似e.parameter.name方法得到文本框中的值没有工作的文件的用户界面,例如,在主界面

================================================== ===========

var app = UiApp.createApplication().setWidth(455).setTitle('My UiApp Sidebar');
var panel = app.createVerticalPanel()
var textBoxA =   app.createTextBox()
                    .setId('textBoxA')
                    .setName('textBoxA').setTag('textBoxA');


var clickButton=app.createButton("Paste")
                   .setId("PasteTest")
                   .addClickHandler(pasteHandler) 


var pasteHandler = app.createServerChangeHandler('readTextbox');
pasteHandler.addCallbackElement(panel);

panel.add(textBoxA);
panel.add(clickButtion);
app.add(panel);
DocumentApp.getUi().showSidebar(app);

================================================== ====================

那么在事件处理程序

readTextbox(e){
  var app = UiApp.getActiveApplication(); 
var boxValue=e.parameter.textBoxA;
  return app;
}

在boxValue回报undifined,该e.parameter.textBoxA_Tag也没有工作,我把日志e.paramter,不textBoxA在那里。

它工作在电子表格UI精美,看起来不支持文档的用户界面非常好

Answer 1:

尝试把事情按正确的顺序,它会工作。

测试文档这里

function xx(){
  var app = UiApp.createApplication().setWidth(455).setTitle('test sideBar with textBox');
  var panel = app.createVerticalPanel().setStyleAttribute('padding','25px')
  var textBoxA =   app.createTextBox()
                    .setId('textBoxA')
                    .setName('textBoxA').setTag('textBoxA');

  var pasteHandler = app.createServerChangeHandler('readTextbox');
  pasteHandler.addCallbackElement(panel);

  var clickButton=app.createButton("type anything and click here to get the textBoxValue")
                   .setId("PasteTest")
                   .addClickHandler(pasteHandler) 

  panel.add(textBoxA);
  panel.add(clickButton);
  app.add(panel);
  DocumentApp.getUi().showSidebar(app);
}

function readTextbox(e){
  var app = UiApp.getActiveApplication(); 
  var boxValue=e.parameter.textBoxA;
  var butn = app.getElementById('PasteTest').setHTML(boxValue);
  return app;
}


文章来源: UI get value function not work in Document App