Selecting an item on a Listbox
We'd usually like to know which item will be selected on a Listbox. In ZKGrails 2, we can handle the onSelect event using the following syntax: $('#master').on('select', { def catId = $(it).val() def cat = Category.read(catId) $('#detail').load(cat.products) }) In the above code, there is a Listbox with id "master". When an item of the master Listbox is selected, we can get: 1. the selected item using expression **$(it).getSelectedItem()** or **it.target.selectedItem**. 2. the selected value using **$(it).val()**. Please note that the **it** variable in the block is of type [SelectEvent](http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/event/SelectEvent.html). A selected value is a "value" of Listitem inside the Listbox. In the below example, the value is a Category's id. $('#master').append { for(cat in categories) { listitem(value: cat.id) { listcell(label: cat.id) listcell(label: cat.name) } } }












