我正在UiApp中创建一个表单来收集用户数据。根据他们在页面上的答案,我需要转到基于页面的答案。说我有三页。用户完成第一页。我使用一个按钮和serverhandler来调用一个运行的函数,如果语句如下:
if(value1 == s1 && value2 == s2){
app.getElementById('page1').setVisible(false);
app.getElementById('page2').setVisible(true);
}
这很好用。我在第二页。从那里点击下一个按钮,然后调用一个syncText'函数,该函数将使用此方法加载用户数据:How To Allow Users to Review Answers before Submiting Form?
一切都好。问题来自于我在第一页,我需要转到第三页和syncText。
if( value1 != s1){
app.getElementById('page1').setVisible(false);
app.getElementById('page3').setVisible(true);
syncText()
}
这不起作用。如何在Google的UiApp中的If语句中调用函数?
我知道我可以简单地将该函数重写为if语句,但我的真实形式要复杂得多,我想避免重复自己。任何帮助?
更新:所以看起来函数正在被调用,但它无法从表单中找到值。如何将表单值放入此函数中?
这是一个完整的示例代码:
function doGet(e){
var app = UiApp.createApplication();
var appPanel = app.createVerticalPanel();
var form = app.createFormPanel();
var panel1 = app.createGrid(4,5).setId('panel1');
var firstNameLabel = app.createLabel("First Name:");
var firstName = app.createTextBox().setName('firstName').setId('firstName');
var lastNameLabel = app.createLabel("Last Name:");
var lastName = app.createTextBox().setName('lastName').setId('lastName');
var emailLabel = app.createLabel('Your Email');
var email = app.createTextBox().setName('email').setId('email');
var testing = app.createServerHandler('testing').addCallbackElement(form);
var button1 = app.createButton('Go to Review');
var info1 = app.createLabel("Please Enter First Name")
.setVisible(false)
.setStyleAttribute('color', 'red');
var info2 = app.createLabel("Please Enter Last Name")
.setVisible(false)
.setStyleAttribute('color', 'red');
var info3 = app.createLabel("Please Enter Email")
.setVisible(false)
.setStyleAttribute('color', 'red');
panel1.setWidget(0,0, firstNameLabel);
panel1.setWidget(0,1, firstName);
panel1.setWidget(0,2, lastNameLabel);
panel1.setWidget(0,3, lastName);
panel1.setWidget(1,1, info1);
panel1.setWidget(1,3, info2);
panel1.setWidget(2,0, emailLabel);
panel1.setWidget(2,1, email);
panel1.setWidget(2,3, button1);
panel1.setWidget(3,1, info3);
app.add(form);
appPanel.add(panel1);
form.add(appPanel);
var panel2 = app.createGrid(4,5).setId('panel2').setVisible(false);
var reviewFirstNameLabel = app.createLabel("First Name:");
var reviewFirstName = app.createLabel().setId('reviewFirstName');
var reviewLastNameLabel = app.createLabel("Last Name:");
var reviewLastName = app.createLabel().setId('reviewLastName');
var reviewEmailLabel = app.createLabel('Your Email:');
var reviewEmail = app.createLabel().setId('reviewEmail');
var submitButton = app.createSubmitButton('Submit');
var button2 = app.createButton('Edit Response');
panel2.setWidget(0,0, reviewFirstNameLabel);
panel2.setWidget(0,1, reviewFirstName);
panel2.setWidget(0,2, reviewLastNameLabel);
panel2.setWidget(0,3, reviewLastName);
panel2.setWidget(1,0, reviewEmailLabel);
panel2.setWidget(1,1, reviewEmail);
panel2.setWidget(2,0, button2);
panel2.setWidget(3,0, submitButton);
appPanel.add(panel2);
//
var editResponse = app.createClientHandler()
.forTargets(panel1).setVisible(true)
.forTargets(panel2).setVisible(false);
button1.addClickHandler(testing);
button2.addClickHandler(editResponse);
return app;
}
function syncText(e){
var app = UiApp.getActiveApplication();
app.getElementById('reviewFirstName').setText(e.parameter.firstName));
app.getElementById('reviewLastName').setText(e.parameter.lastName);
app.getElementById('reviewEmail').setText(e.parameter.email);
app.getElementById('panel1').setVisible(false);
app.getElementById('panel2').setVisible(true);
return app;
}
function testing(e){
var app = UiApp.getActiveApplication();
var firstName = e.parameter.firstName;
var lastName = e.parameter.lastName;
var email = e.parameter.email;
if(firstName != ""){
syncText();
}
错误现在说参数未定义?所有值都构成了测试函数检出,但我似乎无法从syncText()获取值。有关实现此功能的任何帮助吗?
答案 0 :(得分:0)
更好的方法是在每个页面添加课程“页面”。
并且有一些功能,如
function enablePage(page_num)
您隐藏每个.page对象,然后按ID启用必要的。