0
我正在使用CellTable顯示2列的面額和數量的GWT應用程序。數量值可編輯時,面額值不可編輯。如何獲取CellTable單元的值
我設想是,如果用戶選擇,例如,5面額和20的數量,總文本框會自動與5 * 20 = 100。
我的問題是填充什麼,我怎麼能檢索單元格的值,以便我可以進行乘法運算。
PS:這些值都存儲在數據庫表中。
我正在使用CellTable顯示2列的面額和數量的GWT應用程序。數量值可編輯時,面額值不可編輯。如何獲取CellTable單元的值
我設想是,如果用戶選擇,例如,5面額和20的數量,總文本框會自動與5 * 20 = 100。
我的問題是填充什麼,我怎麼能檢索單元格的值,以便我可以進行乘法運算。
PS:這些值都存儲在數據庫表中。
您可以隨時將一個selectionModel附加到celltable中以獲取當前選定的行,然後獲取當前選定的對象,並依次獲取它們的值。我不完全確定下一個陳述,但你也可能想使用FieldUpdater。請參閱GWT文檔here
樣品:
模型選擇
SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
table.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
Contact selected = selectionModel.getSelectedObject();
if (selected != null) {
Window.alert("You selected: " + selected.name);
}
}
});
FieldUpdater:
// Add a field updater to be notified when the user enters a new name.
nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
@Override
public void update(int index, Contact object, String value) {
// Inform the user of the change.
Window.alert("You changed the name of " + object.name + " to " + value);
// Push the changes into the Contact. At this point, you could send an
// asynchronous request to the server to update the database.
object.name = value;
// Redraw the table with the new data.
table.redraw();
}
});
O.k我稍後會嘗試一下,給feedback.Thanks。 – CodeMarshal
謝謝Onker,它工作得很好。 – CodeMarshal
@CodeMarshal不會獲得代表,但如果您將其標記爲接受和/或投票,它將不再顯示爲開放問題,並且其他具有相同疑問的人將會得到幫助...... – Onkar