我的 Google Apps 脚本中的 ServerClickHandler 似乎有问题。运行我的应用程序并提交按钮时,错误消息是“遇到错误:必需:必需”有谁知道为什么会发生这种情况?
var User = new Object(),
Url = new Object();
// Startet die Web-App
function doGet() {
User.email = Session.getActiveUser().getEmail();
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();//Create a panel which will hold all the elements
var longUrlLabel = app.createLabel( 'lange E-Mail hier eingeben - Kurzlink wird dann per E-Mail zugesendet' );
var longUrlBox = app.createTextBox().setName( 'longUrl' )
.setText( 'http://www.' );
var longUrlLabelInfo = app.createLabel().setId( 'shortUrlLabelInfo' ).setVisible( false );
var button = app.createButton( 'Ausführen' );
var handler = app.createServerClickHandler( 'buttonOnClickListener' );
//createHandler for the Button-onClick-Event.
handler.addCallbackElement( panel );
button.addClickHandler( handler ); //Add this handler to the button
//Add all the UI elements to the panel
panel.add( longUrlLabel )
.add( longUrlBox )
.add( button );
app.add( panel );//Add the panel to the application
return app;
}
function buttonOnClickListener( eventInfo ) {
var app;
Url.long = eventInfo.parameter.longUrl.toString();
Url.short = UrlShortener.Url.insert( UrlShortener.newUrl().setLongUrl( Url.short ) );
sendMail();
app = UiApp.getActiveApplication();
app.getElementById( 'longUrlLabelInfo' ).setVisible(true).setText( Url.short );
return app;
}
function sendMail() {
GmailApp.sendEmail( User.email, "UrlShortener", Url.long+" -> "+Url.short );
}