2012-07-31 29 views
0

第一次在StackOverFlow!在應用程序腳本中輸入類型

我正在構建一個應用程序,它通過UI Form TextBox接受一個值。一旦表單被提交,它會調用一個方法,然後在該值上附加「/」。問題在於.append()不可用,因爲getElementById()返回一個GenericWidget對象,因此無法像操作字符串一樣對其進行操作。我已經嘗試在var userinput = app.getElementById('input')。toString;類型轉換中使用.toString()調用,然後使用userinput = userinput.toString。

我一直在使用Apps腳本大約一個月和幾天,現在我認爲投射到除GenericWidget以外的其他類型對於任何想在經過傳遞後以特定類型的方式修改值的人會有幫助該值爲另一種方法。

我也做了一些研究,試圖爲我的問題找到解決方案,但像過去幾次使用Apps腳本一樣,我發現由於這是一種年輕的語言,因此沒有那麼多有用的信息正如Javascript,HTML和XML等語言一樣。任何幫助表示讚賞。

回答

2

您必須使用e.parameter.textBoxName獲取textBox值,然後爲textBox重新賦值。一個簡短的例子將更加明確

function doGet(){ 
var app = UiApp.createApplication(); 
var textbox = app.createTextBox().setName('txt').setId('txt') 
// add other elements, handlers, callBackElements, etc... 
} 

function changetext(e){ 
var app = UiApp.getActiveApplication(); 
var textBoxValue = e.parameter.txt ; // get the value in the text box 
var txtBoxWidget = app.getElementById('txt') ; get the widget by its ID 
txtBoxWidget.setText(textBoxValue+'/'):// assign the modified value 
return app ;// update the UI with new value 
} 
+0

太棒了。我沒有想到直接從框中拉出參數。我剛剛通過ElementById()處理傳遞事件。萬分感謝! – 2012-07-31 18:40:03

相關問題