Wicket中是否有東西兩個下拉選項,這樣第一個dopDownChoice的第一個選擇會改變第二個選項的所有選項?Wicket,DropDownChoice選擇如何更改另一個DropDownChoice的選項?
回答
您應該使用第一個選項的值來確定第二個值的值。
我這個例子中,我選擇使用觸發Ajax更新並執行值更改的AjaxFormComponentUpdatingBehavior
。我提供了第二個DropDownChoice
與第一個選定國家的聯邦國家的簡單示例。
請注意,我在這個例子中使用了wicket 1.4,不過在新版本中不應該有太大的不同。
// two countries
final String aut = "AUT";
final String ger = "GER";
// their states
final List<String> autStates = Arrays.asList(new String[] { "V", "T", "S", "W" });
final List<String> gerStates = Arrays.asList(new String[] { "NRW", "B", "BW" });
// mapping, you should really get this data from a service or have a constant
final Map<String, List<String>> countryToState = new HashMap<String, List<String>>(2);
countryToState.put(aut, autStates);
countryToState.put(ger, gerStates);
// the container to send back via ajax
final WebMarkupContainer cont = new WebMarkupContainer("cont");
cont.setOutputMarkupId(true);
add(cont);
final Model<String> stateModel = new Model<String>();
final DropDownChoice<String> countries = new DropDownChoice<String>("countries", new Model<String>(), new ArrayList<String>(countryToState.keySet()));
final DropDownChoice<String> states = new DropDownChoice<String>("states", stateModel, new LoadableDetachableModel<List<String>>() {
@Override
protected List<String> load() {
final String country = countries.getModelObject();
final List<String> list = countryToState.get(country);
return list != null ? list : new ArrayList<String>(0);
}
});
countries.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
// just add the container to see the results
target.addComponent(cont);
}
});
cont.add(countries);
cont.add(states);
第一DropDownChoice
應該更新Model
秒DropDownChoice
基於並添加第二DDC到AjaxRequestTarget
。
This constructor接受該模型,並且可以存儲對其的引用以便能夠對其進行更改。
這一個? DropDownChoice(String id,IModel <?extends List extends T>> choices)我沒有得到它的工作方式,例如,第一個ddc有1,2和3個選項。當我選擇1,在第二個ddc我想看到(例如)4,5,6選項。當我選擇2時,我想看到7,8,9。這些選項將在哪裏初始化?謝謝:) – evilkorona
好吧,你剛纔寫到了,雖然在自然語言中... ...在處理數值變化的方法中,你應該檢查 - 它當前選定的值是1,其他DDC模型包含4 5 6,如果2 - 包含7 8 9. –
好的,謝謝!我現在就試試吧! :D – evilkorona
- 1. 如何在DropDownChoice Wicket中保留「選擇一個」選項?
- 2. 覆蓋Wicket中DropDownChoice的選擇
- 3. Wicket DropDownChoice格式
- 4. DropDownChoice - 沒有選擇,值-1?
- 5. Wicket中的分隔符DropDownChoice
- 6. Wicket - 使用Scala獲取DropDownChoice中的選定項目
- 7. Wicket - DropDownChoice - 選項的標題(工具提示)
- 8. Wicket:延遲加載DropDownChoice
- 9. Wicket DropDownChoice設置模型值
- 10. Wicket DropDownChoice渲染器問題
- 11. Wicket調色板與dropdownchoice
- 12. Wicket - DropDownChoice POJO物業模型
- 13. Wicket - DropDownChoice + ChoiceRenderer - 預先選擇不起作用
- 14. Wicket - 如何使用SelectOption和DropDownChoice?
- 15. DropDownChoice獲取重複的選擇
- 16. 檢票器:在DropDownChoice項目選擇事件中更新模型
- 17. 檢票DropDownChoice跳到某些選擇
- 18. 如何在第一個dropdownchoice中選擇值時在第二個dropdownchoice中添加值?
- 19. DropDownChoice設置中選擇一個特定的索引
- 20. DropDownChoice onSelectionChnaged
- 21. 如何更改一個選擇的選項,同時選擇另一個?
- 22. 如何在另一個選擇中使選擇選項更改選項
- 23. DropdownChoice Ajax的更新而改變
- 24. DropDownChoice不顯示選定的值
- 25. 如何根據所選的另一選擇選項更改選擇選項?
- 26. 是否可以禁用Wicket DropDownChoice中的某些項目?
- 27. 檢票口 - DropDownChoice與對象選中
- 28. 當我更改AngularJS中另一個選擇選項的值時,如何更改選擇選項值?
- 29. 便門:Dropdownchoice
- 30. 兩個選擇選項更改時的一個選擇框選項更改
非常感謝你!!!這就是我想知道的一切!:) – evilkorona