2

I'm trying to load values retrieved from ScriptDb into an interface application developed within an interface built with GUI Builder. I've loaded the interface via:

var app = UiApp.createApplication();
app.add(app.loadComponent("ScriptDBUi"))

Now that it's loaded I would like to load values into text boxes to display ScriptDb values, however when I try to use setValue or setText, I'm notified that properties can't be changed or modified.

Can you point me in the right direction to be able to interact with UI elements?


Here's some additional code:

function ReadScriptDb() {
var DB = ScriptDb.getMyDb();
var Ob = DB.query({Number: "0002"}).next();
var Ui = doGet()
var TextBox = Ui.getElementById("Project")
TextBox.setText(Ob.Project)
}

function doGet() {
  var app = UiApp.createApplication();
  app.add(app.loadComponent("ScriptDBUi"));
  return app;
}

I've then published this simple script as a Web App so I can test the Ui. After publishing i'll get 1 of 2 things depending on my changes: 1 - The text block doesn't update with the value returned (..i've debugged to insure that Ob.Project is returning a string value), or I've been prompted that i cant assign or modify a value.

Thanks for any insights you can offer.

4

2 回答 2

0

感谢阿伦的帮助。最后,我不了解代码正在处理的顺序。这就是它最终所做的。基本上(..我相当愚蠢)我没有调用 ReadScriptDb,因为我不明白 doGet() 是我的应用程序的入口点。我将“应用程序”传递给我的 ReadScriptDb 函数,然后再次返回到 doGet,一切正常。谢谢你指路。

function ReadScriptDb(app) {
var DB = ScriptDb.getMyDb();
var Ob = DB.query({Number: "0002"}).next();
var Project = Ob.Project;
var TextBox = app.getElementById("Project");
TextBox.setText(Project);
return app;
}

function doGet() {
  var app = UiApp.createApplication();
  app.add(app.loadComponent("ScriptDBUi"));
   ReadScriptDb(app)
  return app;
}

这个参考帮助我清除了它: UI服务

“..doGet 函数是在用户访问部署脚本的 URL 时运行的函数..”

干杯

于 2012-11-03T13:59:07.490 回答
0

你可以在这里读更多关于它的内容 -

https://developers.google.com/apps-script/gui_builder#extending

您的代码看起来像这样(未经测试)

var app = UiApp.createApplication();
app.add(app.loadComponent("ScriptDBUi"))
var textBox = app.getElementById("myTextBoxName");//ID you gave in the GUI builder
textBox.setText("Hello world");

编辑 -

在回调函数中,您需要使用UiAp.getActiveApplcation而不是 createApplication

Your code should be this - 
function ReadScriptDb() {
var DB = ScriptDb.getMyDb();
var Ob = DB.query({Number: "0002"}).next();
var Ui = UiApp.getActiveApplication();//CHANGED THIS
var TextBox = Ui.getElementById("Project")
TextBox.setText(Ob.Project)
}

function doGet() {
  var app = UiApp.createApplication();
  app.add(app.loadComponent("ScriptDBUi"));
  return app;
}
于 2012-11-02T18:44:13.003 回答