我找不到一种方法来读取UI ListBox对象中的项目。我在Google Web Toolkit中搜索并找到了getItemCount()和getItemText()等一些方法,但在javascript中使用该对象时它们不可用.....
有什么想法吗?
答案 0 :(得分:1)
您必须通过服务器端调用传递列表框小部件以从中获取所选数据:
function doGet(){
var app = UiApp.createApplication();
var lb = app.createListBox();
lb.setName("calName") //name used to fetch selected result
.addItem("Text Option One", "1")//options for selection
.addItem("Text Option Two","");//first peram display text and second peram value
app.add(lb); // adds listbox to display
app.add(app.createButton("Click Me")//create button
.addClickHandler(app.createServerHandler("showResult") // Create server side execution to handel click
.addCallbackElement(lb))); // add list-boxas element to be passed to server as parameter
return app;
}
function showResult(e){
var app = UiApp.getActiveApplication();
var res = e.parameter.calName;//parameter name same as list-box name given
app.add(app.createLabel("Selected option is " + res));//displays selected option
return app;
}
只需创建测试应用并保存版本,将此代码用于应用程序并在部署后查看最新代码。