NDEFRecord: thuộc tính data
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Thuộc tính data của giao diện NDEFRecord trả về một DataView chứa các byte thô của tải trọng bản ghi.
Giá trị
Một DataView chứa dữ liệu tải trọng được mã hóa của bản ghi.
Ví dụ
Ví dụ sau lặp qua các bản ghi trong một đối tượng NDEFMessage được lấy từ NDEFReadingEvent.message. Sau khi chọn bản ghi dựa trên mediaType của nó, nó giải mã nội dung được lưu trong thuộc tính data.
js
const ndef = new NDEFReader();
await ndef.scan();
ndef.onreading = (event) => {
const decoder = new TextDecoder();
for (const record of event.message.records) {
if (record.mediaType === "application/json") {
const json = JSON.parse(decoder.decode(record.data));
const article = /^[aeio]/i.test(json.title) ? "an" : "a";
console.log(`${json.name} is ${article} ${json.title}`);
}
}
};
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Web NFC> # dom-ndefrecord-data> |