How can I get all selected files by JS api

I use the latest Nextcloud Server version _( 31.0.2). I want to get all selected files by JS api, what api can I use. currently I use the code below

const checkboxes = document.querySelectorAll('.checkbox-radio-switch__input[type="checkbox"]');

        const selectedItems = Array.from(checkboxes)
            .filter(checkbox => checkbox.checked)
            .map(checkbox => {
                const tr = checkbox.closest('tr');
                if (!tr) return null;

                const fileId = tr.getAttribute('data-cy-files-list-row-fileid');

                const checkboxTd = checkbox.closest('td');
                const nameTd = checkboxTd?.nextElementSibling?.classList.contains('files-list__row-name')
                    ? checkboxTd.nextElementSibling
                    : Array.from(tr.querySelectorAll('td')).find(td =>
                        td.classList.contains('files-list__row-name')
                    );

                const nameElement = nameTd?.querySelector('.files-list__row-name-');
                const fileName = nameElement?.textContent.trim() || '';

                return {fileId, fileName};
            })
            .filter(item => item !== null && item.fileId !== null);

        const checkedCount = selectedItems.length;
        if(checkedCount === 0) {
            showError('plase check at least one file')
        }
        console.log( checkedCount);
        console.log( selectedItems);

but because of the lazy load so I can not get all selected files.

Hey @luger1990,

I am not sure what you want to achieve here. Digging through the attributes might be not too portable to be honest. So, you might want to state the problem that you want to solve.

In any case, I expect the required functions to be part of the @ nextcloud/files NPM package if present at all. Its code is here and the docs can be found online as well.

Cheers
Chris