Select multiple items in listbox based on array with values
I'm submitting a ... (check one with "x")
[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Current behavior Loading selected items (with ngModel) into the listbox only works with primitives as value (string, integer, ...), but when the value is an object there is strange behavior (e.g. items are not selected, when selecting an item that is already in the list it adds the item as a duplicate to the list, to remove the item you have to deselect twice to get rid of it)
Expected behavior load selected list items from a list of objects
Minimal reproduction of the problem with instructions
HTML
<p-listbox multiple="multiple" checkbox="checkbox" [options]="list"
[(ngModel)]="selectedList" filter="true"
appendTo="body"></p-listbox>
TS
public list= [
{ label: 'one', value: { id: '111' } },
{ label: 'two', value: { id: '222' } },
{ label: 'three', value: { id: '333' } }
]
public selectedList: any = []
ngOnInit() {
this.selectedList = [{ id: '222' }];
}
I have the same problem. Any solution?
Not a real solution, but I use two arrays now (one with id's and one with the objects) and that works.
I found this here: https://github.com/primefaces/primeng/issues/1010
Unable to replicate, please provide a test case based on plunkr below and we'll review again. I've checked the code and it should work as well.
http://plnkr.co/edit/Wj39h1?p=preview