PrimeNG multiselect select and deselect value

混江龙づ霸主 提交于 2021-02-11 14:24:11

问题


How do we know in primeNG multiselect whether value/object is selected or deselected.

https://www.primefaces.org/primeng/#/multiselect

    onChange    event.originalEvent: browser event
    event.value: Current selected values
    event.itemValue: Toggled item value

event.value always return the latest array of selected values event.itemValue returns the selected/unselected value

I found in the documentation these three events and in debugging I didn't find any selection and deselection attribute.

Any help would be highly appreciated.

Thanks PG


回答1:


Although I am answering it after a long time the question has asked, but it will help others may be.

event.value: Current selected values array

event.itemValue: Toggled item value

To identify whether the checkbox selected or deselected, just check the event.itemValue is present in the event.value array.

if found in the array then selected otherwise take as deselected.

@Thanks




回答2:


var checked = false;
if (event.value.map((a) => a.id == event.itemValue.id).length == 1) {
    checked = true;
}


来源:https://stackoverflow.com/questions/53957352/primeng-multiselect-select-and-deselect-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!