-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hi guys, i have problem with my project, i just can delete only one selected item in my listbox. And now, i have to add some fiture on my listbox that can delete multiple items. i was found attribute checkmark checkmark="true" multiple="true"
. but i don't know how use that attribute sync with my controller, how i know the item was checked?
this is my method in controller
public void deleteDetail() {
detailList.remove(detail);
kalkulasiDiskonGlobal();
}
sorry for my bad english, thanks guys.
Hi there jayskak,
There are a few options depending on your project's structure and pattern. The recommended way to handle listbox with dynamic content is to use a model object containing the values. It can be a flat List (or other types), but the better option is to use ListModelList You can create a ListModelList from your data in composer and assign it as the model for your component. Then, the selection state is available directly on the ListModel with model.getSelection() Here's a fiddle showing how to use that.
Here's the documentation about listmodel and the one about listbox.
If you are creating the listbox content manually instead of using model, you can use selectedItems or selectedIndex from the listbox directly. This is way less efficient in the long run and might cause issues if you are using these methods with another form of component control such as model, so I would not recommend unless you don't a choice.
Hello, use a loop for example:
for(int i=0; i<detailList.size(); i++){
detailList.remove(i);
}
or whit variable/ flag.
for(int i=0; i< detailList.size(); i++) {
if(selectDetail == detailList.get(i)) {
detailList.remove(i);
}
}
Asked: 2020-03-17 21:17:43 +0800
Seen: 8 times
Last updated: Mar 19 '20