FileSystemDirectoryHandle: phương thức entries()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Phương thức entries() của giao diện FileSystemDirectoryHandle trả về một bộ lặp bất đồng bộ mới để lặp qua các cặp khóa-giá trị của các mục bên trong FileSystemDirectoryHandle mà phương thức này được gọi trên đó. Các cặp khóa-giá trị có dạng một mảng như [key, value].
Cú pháp
entries()
Tham số
Không có.
Giá trị trả về
Một bộ lặp bất đồng bộ mới chứa các cặp khóa-giá trị của từng mục bên trong FileSystemDirectoryHandle.
Ngoại lệ
NotAllowedErrorDOMException-
Được ném ra nếu trạng thái
PermissionStatus.statecủa handle không phải là'granted'ở chế độread. NotFoundErrorDOMException-
Được ném ra nếu mục hiện tại không được tìm thấy.
Ví dụ
Dùng vòng lặp for await...of có thể giúp đơn giản hóa quá trình lặp.
const dirHandle = await window.showDirectoryPicker();
for await (const [key, value] of dirHandle.entries()) {
console.log({ key, value });
}
Thông số kỹ thuật
| Specification |
|---|
| File System> # api-filesystemdirectoryhandle-asynciterable> |