值
一個包含記錄編碼後的 payload 資料的 DataView。
示例
以下示例將遍歷 NDEFMessage 物件中的記錄,該物件從 NDEFReadingEvent.message 中檢索。在根據記錄的 mediaType 選擇記錄後,它會解碼 `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}`);
}
}
};
規範
| 規範 |
|---|
| Web NFC # dom-ndefrecord-data |
瀏覽器相容性
載入中…